serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Debug and Trace Log Level mapped to incorrect Source Levels

ATECoder opened this issue · comments

I use Serilog to emit log messages to File, Trace and Console. I then use a TraceListener to filter the trace messages into a queue based on the trace SourceLevels, which I set to Warning (7).

My expectation is that only Error and Warning messages will appear in the queue. While, indeed, Information (SourceLevels 15 and LogLevel 2) messages are blocked, the queue shows both Trace [VRB] and Debug [DBG] messages which should have been mapped from 0, 1 to SourceLevels.Verbose (31).

Is this the expected behavior?

Is it possible that Trace and Debug levels are mapped lower than the SourceLevels.Warning (7) and thus are filtered in? I am aware that Serilog blocks out lower Log Levels whereas Trace Listener Filters block higher Source Levels. Seeing that Information (2) is blocked, as expected, I expected that both Debug and Trace will be blocked.

The Trace Sink uses specific trace functions for levels Information and higher, but just uses Trace.WriteLine for levels below information, which might effect that?

Yep, that will explain this behavior. It looks like the quick solution would be to fork this sink and add the debug and trace levels to the mix. Oh, I see, Trace is limited to levels at or below Information and does not expose the Trace Event method, which is encapsulated in the internal Trace Internal class.

Accepting this limitation, emitting Trace and Debug messages at the Information level will allow the blocking of these messages at the Information level, which better suites my needs. Issue 21