Roadmap › Modern .NET — Hosting, Configuration, DI & Deployment › Module: Hosting, Configuration, DI and Logging
Lessons in this course (9)

6. Logging, OpenTelemetry and health checks

IntermediateMediumLesson 6 of 9
csharp
builder.Logging.ClearProviders().AddConsole();         // providers: Console, Debug, EventLog, Application Insights, Serilog...
builder.Services.AddOpenTelemetry()
    .WithTracing(t => t.AddAspNetCoreInstrumentation().AddHttpClientInstrumentation().AddOtlpExporter())
    .WithMetrics(m => m.AddAspNetCoreInstrumentation().AddRuntimeInstrumentation().AddOtlpExporter());
builder.Services.AddHealthChecks().AddSqlServer(connStr);   // AspNetCore.HealthChecks.SqlServer package
app.MapHealthChecks("/health");

Log levels: Trace < Debug < Information < Warning < Error < Critical. Configure per category in appsettings.json → Logging:LogLevel. .NET Aspire (now just "Aspire") gives a dev-time orchestrator and dashboard with OpenTelemetry out of the box.