Created
February 16, 2016 03:30
-
-
Save zippy1981/8ada8b93cbb9fede2408 to your computer and use it in GitHub Desktop.
Attempt to make a Cursor tail a log file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE AlwaysEncryptedSample; | |
GO | |
SET NOCOUNT ON; | |
DECLARE | |
@Date CHAR(19), | |
@Thread VARCHAR(255), | |
@Level VARCHAR(50), | |
@Logger VARCHAR(255), | |
@User NVARCHAR(50), | |
@ClientIP NVARCHAR(45), | |
@Message VARCHAR(4000), | |
@Exception VARCHAR(2000), | |
@Severity INT; | |
PRINT '-------- Log4netLog --------' | |
DECLARE curLog CURSOR DYNAMIC FORWARD_ONLY | |
FOR | |
SELECT | |
FORMAT([Date],'g'), Thread, [Level], Logger, | |
[User], ClientIP, [Message], Exception, | |
CASE | |
WHEN [Level] = 'Debug' OR [Level] = 'Info' THEN 0 | |
WHEN [Level] = 'Warning' THEN 10 | |
ELSE 16 | |
END | |
FROM Logging.Log | |
--WHERE Date > GETDATE(); | |
OPEN curLog; | |
FETCH NEXT FROM curLog | |
INTO | |
@Date, | |
@Thread, | |
@Level, | |
@Logger, | |
@User, | |
@ClientIP, | |
@Message, | |
@Exception, | |
@Severity | |
WHILE 1=1 | |
BEGIN; | |
IF @@FETCH_STATUS = 0 RAISERROR('%s - %s - %s', @Severity, 1, @Date, @Level, @Message) WITH NOWAIT; | |
ELSE | |
BEGIN; | |
SET @Date = FORMAT(GETDATE(), 'g') | |
RAISERROR('%s - NULL - No Log written sleeping for 5 seconds', 0, 1, @Date) WITH NOWAIT; | |
WAITFOR DELAY '00:00:05'; | |
END; | |
FETCH NEXT FROM curLog INTO | |
@Date, | |
@Thread, | |
@Level, | |
@Logger, | |
@User, | |
@ClientIP, | |
@Message, | |
@Exception, | |
@Severity | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment