When running containerized enterprise APIs in the cloud, relying solely on standard console logging or checking individual container instances is unsustainable. To maintain high availability, quickly diagnose production bugs, and monitor system performance, you need centralized, structured observability.
By pairing Serilog with Azure Application Insights, you can capture rich structured log events across your Clean Architecture solution and stream them directly into Azure for real-time telemetry analysis and custom dashboard visualization.
In this comprehensive guide, we will walk through installing the necessary packages, configuring Serilog sinks, wiring up telemetry in Program.cs, and setting up production dashboards in the Azure Portal.
Step 1: Install Serilog NuGet Packages
To route application logs directly into Azure, your API project requires the Serilog ASP.NET Core integration package and the official Application Insights sink.
Navigate to your YourSolution.API project and run the following terminal commands:
Bash
dotnet add package Serilog.AspNetCore
dotnet add package Serilog.Sinks.ApplicationInsights
Step 2: Configure Application Insights and Serilog in appsettings.json
Add your Application Insights connection string (retrieved from your Azure Portal resource overview) and define your Serilog minimum log levels in your appsettings.json file:
JSON
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=your-instrumentation-key;IngestionEndpoint=https://your-region.applicationinsights.azure.com/"
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
"System": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
}
}
},
"AllowedHosts": "*"
}
Step 3: Initialize Serilog in Program.cs
Configure a bootstrap logger to catch unexpected startup exceptions, then configure Serilog to enrich log contexts and stream telemetry directly to Application Insights.
Update your Program.cs entry point:
C#
using Serilog;
// 1. Create a bootstrap logger to catch early startup errors
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
try
{
var builder = WebApplication.CreateBuilder(args);
// 2. Host Serilog and bind configuration
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.ApplicationInsights(
services.GetRequiredService<Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration>(),
TelemetryConverter.Traces));
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// 3. Register App Insights Telemetry services
builder.Services.AddApplicationInsightsTelemetry();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application terminated unexpectedly during startup.");
}
finally
{
Log.CloseAndFlush();
}
Step 4: Verify Telemetry and Build Azure Dashboards
Once your application is containerized and deployed to Azure App Service (as covered in previous guides), you can verify that logs and telemetry are flowing correctly:
Verify Log Ingestion: Open your Application Insights resource in the Azure Portal, navigate to Monitoring > Logs, and run a basic Kusto query to inspect incoming traces:
Code snippet
traces | project timestamp, message, severityLevel | order by timestamp desc | take 50Monitor Request Failures: Navigate to the Failures blade to inspect any unhandled exceptions or 400/500 HTTP responses intercepted by your Global Exception Handler.
Build Custom Dashboards: Use the Metrics or Workbooks blades to pin request duration graphs, server response codes, and custom performance counters onto a unified monitoring dashboard for your engineering team.
Summary
By integrating Serilog and Application Insights into your ASP.NET Core Clean Architecture API, you achieve complete production visibility:
Structured Logging: Capture rich context (such as user IDs, request paths, and execution times) rather than plain text strings.
Centralized Analytics: Query distributed logs instantly across cloud containers using Kusto query language.
Proactive Monitoring: Set up performance alerts and live metric streams to catch issues before your users do.

Join the conversation! Your thoughts help the community grow.