Introduction

Application monitoring is a critical part of modern software development. Without proper telemetry, diagnosing performance issues and tracking failures becomes difficult. Microsoft provides Application Insights, a powerful monitoring service within Microsoft Azure that helps developers collect, analyze, and act on telemetry data from their applications.

This article provides a step-by-step guide to integrating Application Insights into a .NET Core Web API, including setup, configuration, deployment, and verification.

Prerequisites

Before proceeding, ensure you have:

Step 1: Create an Application Insights Resource in Azure Portal

Sign in to Azure Portal

  1. Navigate to the Azure Portal.

  2. Log in using your Azure credentials.

Create the Resource

  1. Click Create a resource.

  2. Search for Application Insights.

  3. Select it and click Create.

Configure the Resource

Provide the following details:

Click Review + Create, validate the configuration, and then click Create.

Once deployment is complete, the resource is ready for integration.

Step 2: Install Application Insights SDK

To enable telemetry collection in your .NET Core Web API, install the required NuGet package:

Microsoft.ApplicationInsights.AspNetCore

You can install it using:

dotnet add package Microsoft.ApplicationInsights.AspNetCore

After installation, your application is ready to connect with Azure Application Insights.

Step 3: Configure Application Insights in the Application

Retrieve the Connection String

  1. Open your Application Insights resource in Azure Portal.

  2. Go to the Overview section.

  3. Copy the Connection String (recommended) or Instrumentation Key.

Update appsettings.json

Add the following configuration:

{
  "ApplicationInsights": {
    "ConnectionString": "Your_Connection_String_Here"
  }
}

Configure Program.cs

In .NET 6 or later, add:

builder.Services.AddApplicationInsightsTelemetry();

This enables automatic telemetry collection including:

Step 4: Deploy and Verify Telemetry

Deploy the Application

Deploy your Web API to:

Verify Data in Azure Portal

After deployment and a few minutes of activity:

  1. Navigate to your Application Insights resource.

  2. Explore the following sections:

You should start seeing:

Implementing Logging with ILogger

To capture detailed logs, use ILogger in your controller or service.

Example:

private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
    _logger = logger;
}

public IActionResult Index()
{
    _logger.LogInformation("Information log example.");
    _logger.LogError("Error log example.");
    return Ok();
}

These logs can be viewed under:

Application Insights → Transaction Search

Output and Observations

Once the application runs successfully:

This provides a centralized monitoring solution for your application.

Advantages of Using Application Insights

Conclusion

Integrating Application Insights into a .NET Core Web API application is a straightforward yet powerful way to implement monitoring and diagnostics. With minimal configuration, developers can gain deep visibility into application behavior, performance bottlenecks, and runtime exceptions.

For production-grade applications, implementing monitoring is not optional—it is essential. By following the steps outlined in this article, you can ensure that your application is fully equipped with robust telemetry and logging capabilities.