ASP.NET Core Interview Question #154
How is logging configured in ASP.NET Core?
Logging, Error Handling & Background Services Mid-Level Intermediate
Quick Interview Answer
Logging configuration can be supplied through appsettings.json, environment-specific configuration, code, and provider-specific settings. Categories can have different minimum log levels.
Detailed Explanation
Logging configuration can be supplied through appsettings.json, environment-specific configuration, code, and provider-specific settings. Categories can have different minimum log levels.
The framework typically registers standard logging infrastructure when the application builder is created. Applications can add or remove providers and adjust filtering rules.
Production settings should usually suppress overly verbose framework logs while retaining enough application and warning/error information for diagnosis.
Code Example
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
}
}