asp.net-coreblazor-server-sideiloggeriloggerfactory

Why is ASP.NET ILogger ignoring my log levels?


I am using the ASP.NET ILogger system in a Blazor server app.

I instantiate it as follows:

using (var loggerFactory = LoggerFactory.Create(loggingBuilder => loggingBuilder
           .AddConfiguration(config)
           .AddJsonConsole()
           .AddDebug()))
{
    logger = loggerFactory.CreateLogger<Program>();
}
logger.LogInformation("Application starting up");

// some code

// this is true
if (builder.Environment.IsDevelopment())
{
    builder.Logging.ClearProviders();
    builder.Logging.AddJsonConsole();
    builder.Logging.AddDebug();
}

And then I use it as follows (via injection):

private ILogger<AzureBlobService> Logger { get; }

And here's the appSettings.json (LouisHowe, ThirdPartyServices, CommonUtilities, & Microsoft are namespaces):

"Logging": {
    "LogLevel": {
        "Default": "Warning",
        "LouisHowe": "Information",
        "ThirdPartyServices": "Information",
        "CommonUtilities": "Information",
        "Microsoft": "Warning"
    },

    "Debug": {
        "IncludeScopes": true
    },

    "Console": {
        "FormatterName": "simple",
        "FormatterOptions": {
            "SingleLine": true,
            "IncludeScopes": true,
            "TimestampFormat": "HH:mm:ss ",
            "UseUtcTimestamp": true,
            "JsonWriterOptions": {
                "Indented": true
            }
        }
    },
},

So why do I get log messages like this:

{
  "Timestamp": "23:28:31 ",
  "EventId": 0,
  "LogLevel": "Debug",
  "Category": "ThirdPartyServices.AzureStorage.AzureBlobService",
  "Message": "Creating container users-private with access None",
  "State": {
    "Message": "Creating container users-private with access None",
    "containerName": "users-private",
    "accessType": "None",
    "{OriginalFormat}": "Creating container {containerName} with access {accessType}"
  },
  "Scopes": []
}

In this case ThirdPartyServices is set to Information and this log message is Debug.


Solution

  • Another developer added logging configuration to the appSettings.development.json file (he thought it was for him only). As we were not setting logging in there, I didn't look.

    My bad.

    Anyways, check not just the environment, but the secondard appSettings.{env}.json file.