A log category is a string identifier attached to each log message. It identifies the component that created the message and helps separate application, framework, and service output. section 26.2.1 section 26.2.2
Use categories to make logging identifiable and controllable:
- Inject ILogger<T> to use the fully qualified name of T as the category, which is the usual convention. section 26.2.2
- Inject ILoggerFactory and call CreateLogger("RecipeApp.RecipeService") when an arbitrary category string is useful. section 26.2.2
- Filter messages by category, log level, and provider; the most specific matching rule determines whether each provider writes the message. section 26.4
A service with a category
public class RecipeService { private readonly ILogger _log; public RecipeService(ILoggerFactory factory) { _log = factory.CreateLogger("RecipeApp.RecipeService"); } } The logger records RecipeApp.RecipeService as the category. Unless custom naming is needed, inject ILogger<RecipeService> instead; its generic type supplies the category automatically. section 26.2.2
Listing 26.7 The log filtering configuration section of appsettings.json
{
"Logging": {
"LogLevel": { #1
"Default": "Debug", #1
"System": "Warning", #1
"Microsoft": "Warning" #1
},
"File": { #2
"LogLevel": { #2
"Default": "Information" #2
}
},
"Console": { #3
"LogLevel": { #3
"Default": "Debug", #3
"Microsoft": "Warning" #3
}
}
}
}
Inspect category-based filtering alongside default, namespace-specific, and provider-specific log-level rules. section 26.4

