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
Navigate to the Azure Portal.
Log in using your Azure credentials.
Create the Resource
Click Create a resource.
Search for Application Insights.
Select it and click Create.
Configure the Resource
Provide the following details:
Resource Group – Select an existing one or create a new resource group.
Name – Enter a unique name for your Application Insights instance.
Region – Choose the region where your application is hosted.
Resource Mode – Select:
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:
NuGet Package Manager
Package Manager Console
.NET CLI:
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
Open your Application Insights resource in Azure Portal.
Go to the Overview section.
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:
Navigate to your Application Insights resource.
Explore the following sections:
Live Metrics – Real-time monitoring
Transaction Search – Detailed request and log data
Failures – Exception analysis
Performance – Response time and dependency tracking
You should start seeing:
Request count
Response times
Failure rates
Server-side exceptions
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:
Requests are automatically tracked.
Exceptions are logged with stack traces.
Dependencies such as SQL calls are monitored.
Custom logs appear in the telemetry search section.
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.