Introduction
Building a reliable ASP.NET Core application doesn't end with writing clean code and deploying it to production. Once your application is live, you need visibility into its performance, availability, errors, and user behavior. Without proper monitoring, identifying performance bottlenecks or diagnosing production issues can become difficult and time-consuming.
Azure Application Insights is an application performance monitoring (APM) service that helps developers collect telemetry, analyze application health, and troubleshoot issues in real time. It provides deep insights into requests, dependencies, exceptions, logs, and performance metrics, making it an essential tool for modern ASP.NET Core applications.
In this article, you'll learn how to integrate Application Insights into an ASP.NET Core application, explore its key features, and follow best practices for effective application monitoring.
What Is Azure Application Insights?
Azure Application Insights is a cloud-based monitoring service that collects telemetry from your application and presents it through interactive dashboards and analytics.
It automatically tracks various types of application data, including:
HTTP requests
Response times
Exceptions
Dependency calls
Availability
Performance metrics
Custom events
Trace logs
This information helps developers quickly identify and resolve production issues.
Why Use Application Insights?
Monitoring production applications manually is challenging, especially in cloud and distributed environments.
Application Insights provides several benefits:
Real-time monitoring
Automatic telemetry collection
Exception tracking
Performance analysis
Dependency monitoring
Availability testing
Custom telemetry
Interactive dashboards
These capabilities enable teams to detect and resolve problems before they affect users.
Create an Application Insights Resource
Before integrating Application Insights, create an Application Insights resource in Azure.
Once the resource is created, you'll receive a Connection String, which your application uses to send telemetry data.
Store this connection string securely using configuration files, environment variables, or Azure Key Vault.
Install the NuGet Package
Add the official Application Insights SDK to your project.
dotnet add package Microsoft.ApplicationInsights.AspNetCore
This package enables automatic telemetry collection for ASP.NET Core applications.
Configure Application Insights
Register Application Insights during application startup.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApplicationInsightsTelemetry();
If your connection string is stored in configuration, the SDK automatically uses it.
Example in appsettings.json:
{
"ApplicationInsights": {
"ConnectionString": "YOUR_CONNECTION_STRING"
}
}
This configuration allows the SDK to send telemetry to your Azure resource.
Automatic Request Tracking
Once configured, Application Insights automatically tracks incoming HTTP requests.
It records information such as:
Request URL
Response time
HTTP status code
Success or failure
Request duration
This data helps identify slow endpoints and monitor API performance.
Monitor Dependencies
Most applications interact with external resources such as databases, REST APIs, or messaging services.
Application Insights automatically tracks many dependency calls, including:
SQL Server
Azure SQL Database
HTTP services
Azure Storage
Azure Service Bus
Dependency tracking helps identify slow or failing external services that may impact application performance.
Track Exceptions
Unhandled exceptions are automatically captured by Application Insights.
You can also log exceptions manually when additional context is needed.
using Microsoft.ApplicationInsights;
public class ProductService
{
private readonly TelemetryClient _telemetry;
public ProductService(TelemetryClient telemetry)
{
_telemetry = telemetry;
}
public void LogError(Exception ex)
{
_telemetry.TrackException(ex);
}
}
Capturing exceptions with context makes troubleshooting much easier.
Track Custom Events
In addition to automatic telemetry, you can record business-specific events.
telemetryClient.TrackEvent("OrderPlaced");
Custom events can represent actions such as:
User registration
Order placement
File uploads
Payment completion
Report generation
These events provide valuable insights into application usage.

Join the conversation! Your thoughts help the community grow.