serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ILogger.IsEnabled not respected?

bstordrup opened this issue · comments

I have a piece of code looking like this:

if (_logger?.IsEnabled (LogLevel.Debug) == true)
{
    _logger?.LogDebug ("Notification has arrived {notification}", notification);
}

and my SeriLog configuration looks like this:

"SeriLog": {
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },

As far as I understand, the code piece above should not result in a log entry being created, but it actually does. So the ILogger.IsEnabled must be returning true, but I would expect it to return false because the MinimumLevel.Default is set to Information, and the overrides are not set to Debug.

Using version 3.1.0

I'm doing all configuration through the appsettings.json file - nothing is configured in code.
And I have included the .UseSerilog() as the first call after calling the Host.CreateDefaultBuilder.

Best to work through issues like this on SO - this is about proven bugs that only the maintainers could possibly fix; there are many more people on SO, and anyone that will eventually see this will also have a feed on the SO serilog tag.

I'd suggest eliminating issues with the JSON config from your inquiries by doing that programmatically while troubleshooting.
The other thing I'd do is check the correct flowing of the IsEnabled result using just the static Serilog logger.

(My telepathic debugging would be that there is something elevating the log level somewhere outside of what you've shown - out of the box the Serilog default level is Information, and the same holds for most sinks.)