I am attempting to send Information messages to the Windows Event Log using NetCore 3.1's built-in logging.
I have included an EventLog section in my appsettings.json with a default LogLevel of Debug and I am also providing a filter when configuring the logging. Despite this, I can only see Error and Warning messages in the Event Log. It is as if my override of the LogLevel default of Warning is being ignored.
Does anyone know what I'm doing wrong?
In appsettings.json:
"EventLog": {
"LogLevel": {
"Default": "Debug",
"Microsoft.Hosting.Lifetime": "Debug"
}
},
In program.cs:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(
logging =>
{
logging.SetMinimumLevel(LogLevel.Debug);
logging.ClearProviders();
logging.AddFilter("Microsoft", LogLevel.Warning);
logging.AddConsole();
//#if !DEBUG
logging.AddEventLog(
eventLog =>
{
eventLog.SourceName = SERVICE_NAME;
eventLog.Filter =
(source, level) => level >= LogLevel.Debug;
}
);
//#endif
}
)
and also:
_logger.LogError("This is a test error upon startup. Please do not be alarmed. It should be followed by Warning, Information and Debug.");
_logger.LogWarning("This is a test warning upon startup. Please do not be alarmed. It should be followed by Information and Debug.");
_logger.LogInformation("This is a information message upon startup. It should be followed by Debug.");
_logger.LogInformation("This is a debug message upon startup. It should be last in a series of four.");
And from the Event Log:
Warning 5/8/2020 2:36:56 PM SERVICE_NAME 0 None (This is a test warning upon startup. Please do not be alarmed. It should be followed by Information and Debug.)
Error 5/8/2020 2:36:56 PM SERVICE_NAME 0 None (This is a test error upon startup. Please do not be alarmed. It should be followed by Warning, Information and Debug.)
but not the other two expected messages.