ASP.NET Core Web API Interview Question #131

What are common logging levels in ASP.NET Core?

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced

Quick Interview Answer

Common levels are Trace, Debug, Information, Warning, Error, and Critical. The level should reflect the operational significance of an event rather than simply how much text is being logged.

Detailed Explanation

Common levels are Trace, Debug, Information, Warning, Error, and Critical. The level should reflect the operational significance of an event rather than simply how much text is being logged.

Normal successful requests should not generally be logged as errors. Production logging thresholds should balance diagnostic value, cost, performance, and noise.

Code Example

_logger.LogDebug("Loading product {ProductId}", id);
_logger.LogInformation("Product {ProductId} loaded", id);
_logger.LogWarning("Product {ProductId} not found", id);
_logger.LogError(ex, "Failed to process product {ProductId}", id);