Need help defining UDL for log files
-
My log file format is as seen below. First one is general and the second for error. I have separate log files for each log levels.
"{Level} | {Timestamp:HHmmss-fffff} | {ThreadId} | {TransactionId} | {RequestPath}| {Message:lj}|{NewLine}";
"{Level} | {Timestamp:HHmmss-fffff} | {ThreadId} | {TransactionId} | {RequestPath}| {Message:lj}| {Properties:j} |{NewLine}";
I am trying to get each of them represented by different colours but that is becoming a challenege especially in error log files where properties have exception properties and stack trace which has CRLF in them comparde to info or debug logs where CRLF is only at end of a log line.
Error | 014413-78963 | 6 | ["80001f82-0000-f100-b63f-84710c7967bb"] | /HomePage/SomeController/Login| { ErrorMessage = The system cannot find the file specified., Source = System.Security.Cryptography.Algorithms, StackTrce = at System.Security.Cryptography.CngKeyLite.SomethingSomething(String blobType, ReadOnlySpan`1 keyBlob, Boolean encrypted, ReadOnlySpan`1) at System.Security.Cryptography.CngPkcs8.ImportPkcs8(ReadOnlySpan`1 keyBlob) at System.Security.Cryptography.CngPkcs8.ImportPkcs8PrivateKey(ReadOnlySpan`1 source, Int32& bytesRead) blah blah --- End of stack trace from previous location --- Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)","TargetSite":"Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle ImportKeyBlob(System.String, System.ReadOnlySpan`1[System.Byte], Boolean, System.ReadOnlySpan`1[System.Char])","Type":"Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException"}} |
Once I get each delimited fields color coded, I would like to have json language style applied to properties section too
Thanks!
-
UDL is primarily for keyword-based languages. Logfiles are much more “positional”-based (or, at least, pattern-based).
The plugin CSVLint adds a lexer plugin (so it behaves more like a builtin lexer than a UDL). I think it might be able to specify alternate characters instead of comma
,
for the separator (but I don’t have the plugin installed right now, so cannot check for you).Alternately, there’s the AnalysePlugin, which allows you to set up multiple regex to highlight various patterns; it’s primary use is to apply multiple highlights to log files, so it’s probably pretty close to what you want.
I would like to have json language style applied to properties section too
Yeah, UDL cannot inherit from a builtin lexer, so wouldn’t be able to do that. And the CSVLint probably couldn’t even approximate that. OTOH, the AnalysePlugin, with its regex, would probably be able to get something reasonable.