Monitoring .NET applications is essential for maintaining performance, reliability, and availability in production environments. Azure Application Insights is a powerful Application Performance Management (APM) service in Microsoft Azure that provides real-time telemetry, distributed tracing, dependency tracking, and advanced analytics for ASP.NET Core, .NET Web API, and background services. This guide explains how to monitor .NET applications using Azure Application Insights with practical configuration steps.
What is Azure Application Insights?
Azure Application Insights is a cloud-based monitoring and observability service that collects telemetry data such as requests, exceptions, performance metrics, logs, and dependency calls. It helps developers detect performance bottlenecks, diagnose failures, and analyze user behavior.
Core monitoring capabilities include:
Request and response tracking
Exception monitoring
Distributed tracing
Dependency monitoring (SQL, HTTP, external APIs)
Live metrics stream
Custom telemetry and logging integration
It integrates seamlessly with ASP.NET Core, .NET Core Web API, Worker Services, and Azure-hosted workloads.
Prerequisites
Before configuring Application Insights for .NET applications, ensure:
An active Microsoft Azure subscription
A .NET or ASP.NET Core application
Azure CLI installed (optional)
Visual Studio or .NET CLI
Step 1: Create an Azure Application Insights Resource
You can create the resource from Azure Portal or using Azure CLI.
Using Azure CLI:
az monitor app-insights component create \
--app my-dotnet-app-insights \
--location centralindia \
--resource-group my-monitoring-rg \
--application-type web
After creation, copy the Connection String from the Azure Portal. This will be required in the application configuration.
Step 2: Install Application Insights SDK in ASP.NET Core
Add the required NuGet package:
dotnet add package Microsoft.ApplicationInsights.AspNetCore
Step 3: Configure Application Insights in Program.cs
For .NET 6 or later (Minimal Hosting Model):
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = builder.Configuration["ApplicationInsights:ConnectionString"];
});
var app = builder.Build();
app.MapControllers();
app.Run();
Add the connection string in appsettings.json:
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=YOUR_KEY;IngestionEndpoint=https://centralindia-0.in.applicationinsights.azure.com/"
}
}
Step 4: Monitor Requests and Dependencies
Once configured, Application Insights automatically tracks:
Incoming HTTP requests
Response times
Failed requests
External HTTP calls
SQL queries
Dependency latency
No additional configuration is required for basic telemetry collection in ASP.NET Core applications.
Step 5: Track Custom Events and Metrics
You can send custom telemetry using TelemetryClient.
using Microsoft.ApplicationInsights;
public class OrderService
{
private readonly TelemetryClient _telemetryClient;
public OrderService(TelemetryClient telemetryClient)
{
_telemetryClient = telemetryClient;
}
public void ProcessOrder(string orderId)
{
_telemetryClient.TrackEvent("OrderProcessed", new Dictionary<string, string>
{
{ "OrderId", orderId }
});
_telemetryClient.TrackMetric("OrdersProcessed", 1);
}
}
This enables business-level monitoring in addition to system metrics.
Step 6: Enable Distributed Tracing
Azure Application Insights supports distributed tracing across microservices. If multiple .NET services use Application Insights, correlation IDs are automatically propagated through HTTP headers.
This helps trace end-to-end transactions in microservices architecture deployed on Azure Container Apps, Azure App Service, or Kubernetes.
Step 7: View Logs and Analyze Telemetry
Use Azure Portal to explore:
Failures tab for exception analysis
Performance tab for response time insights
Live Metrics Stream for real-time monitoring
Logs (Kusto Query Language - KQL) for advanced queries
Example KQL query to find failed requests:
requests
| where success == false
| order by timestamp desc
Step 8: Monitor Background Services and Worker Apps
For .NET Worker Services, install:
dotnet add package Microsoft.ApplicationInsights.WorkerService
Then configure:
builder.Services.AddApplicationInsightsTelemetryWorkerService();
This enables telemetry collection for background jobs, queue processors, and scheduled tasks.
Best Practices for Monitoring .NET Applications
Store connection strings in Azure Key Vault
Enable sampling to reduce telemetry cost
Use structured logging with ILogger
Set up alerts for critical exceptions
Configure availability tests
Monitor dependency failures and slow queries
When to Use Azure Application Insights
Azure Application Insights is ideal for:
ASP.NET Core Web APIs
Microservices-based systems
Cloud-native .NET applications
High-traffic production environments
Applications deployed on Azure App Service or Azure Container Apps
Summary
Monitoring .NET applications using Azure Application Insights provides comprehensive observability through real-time telemetry, distributed tracing, dependency tracking, custom events, and advanced analytics. By creating an Application Insights resource in Azure, installing the appropriate SDK for ASP.NET Core or Worker Services, configuring the connection string, and leveraging built-in monitoring features, developers can proactively detect performance issues, diagnose failures, and optimize application reliability. With support for Kusto queries, live metrics, and alerting, Azure Application Insights enables scalable and production-ready monitoring for modern cloud-based .NET workloads.