liveBook · Manning

Appsettings-based logging configuration

As explained in Building Web APIs with ASP.NET Core

Appsettings-based logging configuration sets provider behavior through logging settings in ASP.NET Core configuration files.

Appsettings-based logging configuration controls logging providers through configuration files instead of changing Program.cs. It supports shared rules and environment-specific behavior for an ASP.NET Core application. section 7.2.4

Key implementation points:

  • Define general thresholds under Logging:LogLevel, then add a provider-specific LogLevel subsection when one provider needs different filtering. section 7.2.4
  • For example, set MyBGList to Information generally but Warning for the console provider, suppressing its informational custom message. section 7.2.4
  • Provider settings are not interchangeable: unsupported options, such as Debug provider timestamp settings, are ignored. section 7.2.4

Override console verbosity

Add a Logging:Console:LogLevel:MyBGList value of Warning in appsettings.json, run or hot-reload the application, and check the command prompt for the missing informational message. section 7.2.4

"Logging": {
    "LogLevel": {
      "Default": "Warning",
      "MyBGList": "Information"
    },
    "Console": {
"LogLevel": {        #1
"MyBGList": "Warning"
},
      "FormatterOptions": {
        "TimestampFormat": "HH:mm:ss ",
        "UseUtcTimestamp": true
      }
    }
  }

Use this configuration listing to compare generic logging thresholds with a console-only category override. section 7.2.4

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Demonstrates generic and provider-specific thresholds, then verifies filtering, but defers detailed settings for individual providers.
Examples
Uses the MyBGList category, console provider, Warning threshold, and command-prompt output to demonstrate and verify filtering.
What it assumes
Assumes familiarity with logging providers, categories, log levels, appsettings.json, and the Program.cs configuration alternative.
What you can do after
Configure logging thresholds in appsettings.json and verify provider-specific behavior by running or hot-reloading the application.
How it connects
Connects logging providers with log levels, categories, configuration files, and environment-specific configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.