Monitoring .NET applications is essential for ensuring performance, reliability, scalability, and user experience in production environments. Application Insights is an application performance management (APM) service that enables developers and DevOps teams to collect telemetry, analyze performance metrics, track exceptions, monitor dependencies, and gain deep observability into distributed systems.
In modern ASP.NET Core applications, microservices, cloud-native systems, and containerized workloads, Application Insights provides real-time diagnostics, distributed tracing, live metrics, and intelligent anomaly detection. This article explains how to implement Application Insights in .NET applications, configure telemetry, track custom events, monitor dependencies, analyze logs, and apply best practices.
What Is Application Insights?
Application Insights is a monitoring and observability platform that collects telemetry data from applications, including:
Request rates and response times
Failure rates and exceptions
Dependency calls (SQL, HTTP, external APIs)
Performance counters
Custom events and metrics
Distributed traces
It supports ASP.NET Core, worker services, background jobs, Azure Functions, and containerized .NET applications.
Why Monitoring Is Critical for .NET Applications
Without proper monitoring:
Performance bottlenecks remain hidden
Production errors go undetected
Root cause analysis becomes difficult
SLA violations increase
User experience degrades
With Application Insights:
Real-time telemetry is available
Alerts can be configured
Failures are traceable across services
Query-based diagnostics are possible
Trends and anomalies are detectable
Step-by-Step Implementation in ASP.NET Core
Step 1: Install Application Insights Package
Install the required NuGet package:
dotnet add package Microsoft.ApplicationInsights.AspNetCore
Step 2: Configure Application Insights in Program.cs
Register Application Insights services:
builder.Services.AddApplicationInsightsTelemetry();
Provide the connection string in appsettings.json:
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=YOUR_KEY;IngestionEndpoint=YOUR_ENDPOINT"
}
}
Alternatively, configure using environment variables in production.
Step 3: Automatic Telemetry Collection
Once configured, Application Insights automatically tracks:
Incoming HTTP requests
Response times
Failed requests
Unhandled exceptions
SQL dependency calls
Outbound HTTP calls
Example ASP.NET Core controller:
[ApiController]
[Route("api/products")]
public class ProductsController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
return Ok(new { Message = "Monitoring Enabled" });
}
}
Requests to this endpoint are automatically tracked.
Step 4: Track Custom Events
To log custom business events, inject TelemetryClient.
using Microsoft.ApplicationInsights;
public class OrderService
{
private readonly TelemetryClient _telemetryClient;
public OrderService(TelemetryClient telemetryClient)
{
_telemetryClient = telemetryClient;
}
public void PlaceOrder(string orderId)
{
_telemetryClient.TrackEvent("OrderPlaced", new Dictionary<string, string>
{
{ "OrderId", orderId }
});
}
}
This enables tracking domain-specific events.
Step 5: Track Custom Metrics
_telemetryClient.TrackMetric("CartValue", 250);
Custom metrics help monitor KPIs such as revenue, user activity, or transaction count.
Step 6: Track Exceptions Manually
Unhandled exceptions are captured automatically, but manual tracking provides better context.
try
{
ProcessPayment();
}
catch (Exception ex)
{
_telemetryClient.TrackException(ex);
throw;
}
Step 7: Enable Logging Integration
Application Insights integrates with ASP.NET Core logging.
In Program.cs:
builder.Logging.AddApplicationInsights();
Then use ILogger normally:
private readonly ILogger<ProductService> _logger;
_logger.LogInformation("Product retrieved successfully.");
_logger.LogError("Product not found.");
Logs are searchable in the monitoring dashboard.
Monitoring Dependencies
Application Insights automatically tracks dependencies such as:
SQL Server queries
HTTP calls to external APIs
Azure services
Example HTTP dependency tracking:
var response = await _httpClient.GetAsync("https://api.example.com");
The call is automatically recorded with duration and status.
Distributed Tracing in Microservices
In microservices architecture, a single request may pass through multiple services.
Application Insights supports distributed tracing by:
Assigning correlation IDs
Linking request chains
Visualizing service maps
This helps identify latency sources and failure points across services.
Live Metrics and Performance Monitoring
Live Metrics Stream provides:
Real-time request rate
CPU usage
Memory usage
Failed requests
This is useful during production incidents.
Log Analytics and Kusto Query Language (KQL)
Application Insights supports advanced querying using KQL.
Example query to find failed requests:
requests
| where success == false
| order by timestamp desc
Example query for slow requests:
requests
| where duration > 1000
| order by duration desc
These queries help with root cause analysis.
Alerts and Smart Detection
You can configure alerts for:
High failure rate
Increased response time
Exception spikes
Custom metric thresholds
Smart detection uses AI-based anomaly detection to identify unusual behavior automatically.
Application Insights vs Traditional Logging
| Parameter | Traditional Logging | Application Insights |
|---|---|---|
| Real-Time Monitoring | Limited | Yes |
| Distributed Tracing | No | Yes |
| Dependency Tracking | Manual | Automatic |
| Query Language | Basic search | Advanced KQL |
| Alerting | Manual setup | Built-in alert rules |
| Cloud Integration | Limited | Native cloud support |
Application Insights provides full observability compared to simple log files.
Best Practices for Monitoring .NET Applications
Track meaningful custom events
Avoid logging sensitive data
Use sampling to reduce telemetry volume
Implement correlation IDs
Configure alerts proactively
Monitor performance baselines
Combine logs, metrics, and traces
Common Challenges
Excess telemetry volume increases cost
Poor instrumentation leads to noisy data
Missing correlation IDs complicates tracing
Not defining alert thresholds
Proper configuration ensures cost-effective and actionable monitoring.
Summary
Monitoring .NET applications using Application Insights enables real-time observability, performance tracking, dependency monitoring, distributed tracing, and intelligent alerting. By integrating Application Insights into ASP.NET Core applications, configuring telemetry, tracking custom events and metrics, enabling logging integration, and leveraging Kusto Query Language for diagnostics, development teams gain deep operational visibility into production systems. Effective monitoring reduces downtime, improves root cause analysis, enhances user experience, and strengthens overall system reliability in modern cloud-native architectures.

Join the conversation! Your thoughts help the community grow.