C# Interview Question #166
What is logging in ASP.NET Core?
ASP.NET Core, DI & Middleware Senior Advanced
Quick Interview Answer
ASP.NET Core provides the ILogger<T> abstraction for structured application logging.
Detailed Explanation
ASP.NET Core provides the ILogger<T> abstraction for structured application logging.
Structured logging uses message templates and named values instead of constructing large strings manually. This allows log systems to query properties such as ProductId, UserId, or OrderId.
Applications should choose appropriate log levels, avoid logging secrets or sensitive data, and include enough context to diagnose failures without producing excessive noise.
Code Example
public class ProductService
{
private readonly ILogger<ProductService> _logger;
public ProductService(ILogger<ProductService> logger)
{
_logger = logger;
}
public void Process(int productId)
{
_logger.LogInformation(
"Processing product {ProductId}",
productId);
}
}