ASP.NET Core Interview Question #155

What are logging providers in ASP.NET Core?

Logging, Error Handling & Background Services Mid-Level Intermediate

Quick Interview Answer

A logging provider sends log events to a particular destination or logging system. Built-in and platform integrations can write to destinations such as the console, debug output, event sources, or operating-system logging facilities.

Detailed Explanation

A logging provider sends log events to a particular destination or logging system. Built-in and platform integrations can write to destinations such as the console, debug output, event sources, or operating-system logging facilities.

Applications can also integrate structured logging and monitoring platforms through additional providers. Because application code depends on ILogger rather than a provider directly, the destination can change without rewriting business services.

Provider selection should reflect the deployment environment, retention requirements, searchability, alerting, and security needs.

Code Example

var builder = WebApplication.CreateBuilder(args);

builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.AddDebug();