liveBook · Manning

Log category

As explained in Pro ASP.NET Core 7, Tenth Edition

A logging category is a string or type-derived identifier associated with log messages and used to identify their source component and select logging configuration.

A log category identifies the component that generated a message and determines which logging configuration applies. ILogger<T> conventionally derives the category from T, while ILoggerFactory can create one from an explicit string. section 15.3.1 section 15.3.3

A class such as Population produces the Platform.Population category. Logging configuration matches that category directly, by its namespace prefix such as Platform, or through the Default entry when no more specific match exists. section 15.3.3

Use categories to control the detail emitted by different parts of an application:

  • Set a minimum level such as Trace, Debug, Information, Warning, Error, Critical, or None. section 15.3.3
  • Inject ILogger<Population> into an endpoint so its messages carry the Population-derived category. section 15.3.1
  • Use app.Logger in Program.cs for the application category, or create an explicit Pipeline category through ILoggerFactory. section 15.3.1

Filtering routing diagnostics

Set Microsoft.AspNetCore.Routing to Debug while leaving Microsoft.AspNetCore at Warning. Routing diagnostics then appear alongside application messages without increasing every Microsoft category's verbosity. section 15.3.3

Listing 15.24 Configuring the appsettings.Development.json file in the Platform folder
{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information",
      "Microsoft.AspNetCore": "Warning",
      "Microsoft.AspNetCore.Routing": "Debug"
    }
  }
}

Shows a focused appsettings.Development.json configuration that raises routing diagnostics without broadly enabling detailed ASP.NET Core logging. section 15.3.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains type-derived and string categories, hierarchical matching, defaults, and targeted filters, but not logging-provider internals.
Examples
Uses Population, Platform.Population, Platform, Microsoft.AspNetCore.Routing, and Pipeline to demonstrate derived, hierarchical, and explicit categories.
What it assumes
Assumes familiarity with ASP.NET Core logging and configuration while demonstrating category selection from zero through ILogger<T> and strings.
What you can do after
Operate/configure logging filters that increase, reduce, or disable diagnostic detail for selected application components.
How it connects
Connects log categories with ILogger<T>, ILoggerFactory, logging levels, appsettings.json, and ASP.NET Core routing.

Also explained in

Compare how 2 books explain log category →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.