serilog-sinks-eventlog icon indicating copy to clipboard operation
serilog-sinks-eventlog copied to clipboard

Log Levels are not logged correctly

Open grewegreg opened this issue 2 years ago • 0 comments

When writing to the Event Viewer, the log levels Debug and Verbose are logged as Information, and Fatal is logged as Error.

In the file:

https://github.com/serilog/serilog-sinks-eventlog/blob/dev/src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs

Is see the mapping:

static EventLogEntryType LevelToEventLogEntryType(LogEventLevel logEventLevel)
        {
            switch (logEventLevel)
            {
                case LogEventLevel.Debug: 
                case LogEventLevel.Information:
                case LogEventLevel.Verbose:
                    return EventLogEntryType.Information;

                case LogEventLevel.Error:
                case LogEventLevel.Fatal:
                    return EventLogEntryType.Error;

                case LogEventLevel.Warning:
                    return EventLogEntryType.Warning;

                default:
                    SelfLog.WriteLine("Unexpected logging level {0}, writing to the event log as `Information`", logEventLevel);
                    return EventLogEntryType.Information;
            }
        }


Since the [EventLogEntryType](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlogentrytype?view=windowsdesktop-7.0) Enumeration does not contain Debug, Trace, or Fatal, can those Log Levels be written into Categories instead?


![WindowsEventViewer](https://user-images.githubusercontent.com/91921107/211178482-933d76c8-ba5b-469d-ad02-a813e5208948.png)
![WritingToWindowsEventViewer](https://user-images.githubusercontent.com/91921107/211178483-e91ff50a-91d4-42a1-9e14-435674fa891d.png)

grewegreg avatar Jan 08 '23 03:01 grewegreg