dot NET Core includes a built in, extensible logging framework that supports writing log messages to multiple destinations, called providers, such as the console, debug output, Windows Event Log, or third party services like Serilog and Application Insights. You inject an ILogger instance into any class through Dependency Injection and call methods like LogInformation, LogWarning, or LogError, and the framework handles routing those messages to whichever providers are configured, along with support for log levels that control how much detail gets recorded.
public class OrderService {
private readonly ILogger<OrderService> _logger;
public OrderService(ILogger<OrderService> logger) {
_logger = logger;
}
public void PlaceOrder() {
_logger.LogInformation("Order placed successfully");
}
}
Real-world example
A production application logs warnings whenever an external payment API responds slowly, and configures those logs to be sent to Application Insights so the operations team can monitor performance issues in real time.
MVC Filters;What are .NET Core Hosting Models?