DEV Community

Cover image for Monitoring Your .NET Apps with Azure Application Insights
Morteza Jangjoo
Morteza Jangjoo

Posted on

Monitoring Your .NET Apps with Azure Application Insights

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 
Enter fullscreen mode Exit fullscreen mode

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); } } } 
Enter fullscreen mode Exit fullscreen mode

3. Add connection string

Inside appsettings.json:

{ "ApplicationInsights": { "ConnectionString": "InstrumentationKey=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;IngestionEndpoint=https://<region>.in.applicationinsights.azure.com/" } } 
Enter fullscreen mode Exit fullscreen mode

4. Run and watch telemetry

dotnet run 
Enter fullscreen mode Exit fullscreen mode
  • 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 
Enter fullscreen mode Exit fullscreen mode

Top 5 slowest endpoints:

requests | summarize avg(duration) by name | top 5 by avg_duration desc 
Enter fullscreen mode Exit fullscreen mode

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:

  1. Log in → Go to portal.azure.com.
  2. Create a Resource → Search for “Application Insights” and click Create.
  3. 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
    1. Review + Create → click Create to finish.
    2. 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/" } } 
Enter fullscreen mode Exit fullscreen mode

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?

get sample code from github 👈

I’m Morteza Jangjoo and “Explaining things I wish someone had explained to me”

Top comments (0)