If you’re deploying a .NET application, the story doesn’t end when it “just works.” You need to know what’s happening inside your app in production:
- Which endpoints are slow?
- Where are the errors happening?
- Are users experiencing delays?
- Can we catch issues before customers complain?
That’s exactly where Azure Application Insights comes into play.
What is Application Insights?
Application Insights is part of Azure Monitor and acts as an Application Performance Monitoring (APM) service.
It helps you track, analyze, and visualize everything happening in your application.
Highlights:
- Monitor requests, dependencies, and exceptions
- See response times and bottlenecks
- Track user behavior (page views, sessions)
- Set up alerts and dashboards
- View data in real-time with Live Metrics Stream
⚡ Why should you care?
Imagine you built a shiny .NET Core API.
Users say: “It feels slow!”
Without telemetry, you’re left guessing: database? API calls? network?
With Application Insights → you get answers in minutes.
Adding It to an ASP.NET Core App
1. Install package
dotnet add package Microsoft.ApplicationInsights.AspNetCore
2. Update Program.cs
using Microsoft.ApplicationInsights; var builder = WebApplication.CreateBuilder(args); // Enable Application Insights builder.Services.AddApplicationInsightsTelemetry( builder.Configuration["ApplicationInsights:ConnectionString"]); builder.Services.AddSingleton<WeatherService>(); var app = builder.Build(); app.MapGet("/", () => "Hello from App Insights!"); app.MapGet("/weather", (WeatherService service) => { service.GetWeather(); return Results.Ok("Telemetry sent!"); }); app.Run(); public class WeatherService { private readonly TelemetryClient _telemetry; public WeatherService(TelemetryClient telemetry) { _telemetry = telemetry; } public void GetWeather() { _telemetry.TrackEvent("GetWeatherCalled"); _telemetry.GetMetric("WeatherRequests").TrackValue(1); try { throw new Exception("Test Exception!"); } catch (Exception ex) { _telemetry.TrackException(ex); } } }
3. Add connection string
Inside appsettings.json
:
{ "ApplicationInsights": { "ConnectionString": "InstrumentationKey=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;IngestionEndpoint=https://<region>.in.applicationinsights.azure.com/" } }
4. Run and watch telemetry
dotnet run
- Hit
/weather
endpoint → events, metrics, and exceptions will be logged. - Go to Azure Portal → Application Insights → Live Metrics → see the data flowing in .
Example KQL queries
Application Insights uses Kusto Query Language (KQL) to explore telemetry.
Failed requests:
requests | where success == false | order by timestamp desc
Top 5 slowest endpoints:
requests | summarize avg(duration) by name | top 5 by avg_duration desc
Wrap-up
Application Insights makes it easy to:
Monitor performance
Diagnose errors quickly
Understand how users interact with your app
Set up proactive alerts
If you’re running any .NET app in production, Application Insights should be one of your go-to tools.
Before your .NET app can send telemetry to Application Insights, you need a resource in the Azure Portal. Here’s how:
- Log in → Go to portal.azure.com.
- Create a Resource → Search for “Application Insights” and click Create.
- Fill in the details:
- Subscription → choose your subscription
- Resource Group → create one if you don’t already have it (e.g.,
AppInsightsDemoRG
) - Name → choose a unique name
- Region → pick the closest Azure region to your users (e.g., West Europe, Sweden Central)
- Resource Mode → select Workspace-based
- Review + Create → click Create to finish.
- Copy the Connection String → After deployment, go to your new resource → Properties / Overview → copy the Connection String.
Paste that Connection String into your appsettings.json
file:
{ "ApplicationInsights": { "ConnectionString": "InstrumentationKey=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;IngestionEndpoint=https://<region>.in.applicationinsights.azure.com/" } }
Now your app is fully wired up to Azure Application Insights.
💬 What do you think?
Have you tried Application Insights in your projects?
Or do you prefer something else like Serilog + Seq / ELK stack?
I’m Morteza Jangjoo and “Explaining things I wish someone had explained to me”
Top comments (0)