5 Easy Steps to Integrate Azure Application Insights into Your ASP.NET Core Application for Performance Monitoring
This article will guide you on how to add Azure Application Insights in your ASP.NET Core application for tracking application performance.
Application Insights, a feature of Azure Monitor, is an extensible Application Performance Management (APM) service for developers and DevOps professionals provided by Microsoft Azure. Use it to monitor your live application performances.
Creating Application Insights new instance in Azure Portal
Step 1: Go to Azure Portal and search for Application Insights.
After opening, the Application Insights page, click create and fill details in the form, and click on Review + Create. In few minutes, your instance will be created.
You can select the region nearest to your web app-hosted location. If you don’t have a resource group you can create a new one.
Setting up your ASP.NET Core MVC application for monitoring
Open your ASP.NET Core project in Visual Studio. Search and install Microsoft.ApplicationInsights.AspNetCore Nugget Package.
Step 3: Configure Application Insight service in Startup.cs file ConfigureServices method by adding this line
Tip: After testing with the above code, you can add below code to restrict logging metrics in a development environment
Step 4: Get the Application Insights Instrumentation key from Azure Portal
Step 5: Include the Application Insights instrumentation key in your project appsettings.json file.
Tip: Instrumentation Key can also be injected via environment variables.
That’s it !!! Setup is complete
Now you can run applications and explore logs and track live metrics in Azure Portal.
For more details, check out the Microsoft official documentation.