June 23, 2016 by Anuraj
C# ASP.NET ASP.NET Core Application Insights Azure
This post is to about using Application Insights in ASP.NET Core. Application Insights is an extensible analytics platform that monitors the performance and usage of your live ASP.NET Core web applications. To use Application Insights, you need to create one Application Insights. It is still in Preview mode, you can create one using portal.azure.com website.
Once you create an application insight, you need to get the instrumentation key. You can get it from the properties.
Once you get the instrumentation key, you can keep it inside the appsettings.json file, like this.
For using the Application Insights, you need to add “Microsoft.ApplicationInsights.AspNetCore” to the project.json file. I am using RC2 version here.
As mentioned in the earlier post, you need to read the appsettings.json file and populate the Configuration property. In the method ConfigureServices add Application Insights service. You’ll need to add namespace Microsoft.ApplicationInsights.AspNetCore in the using list.
In the method Configure add Application Insights request and exception tracking middleware. Please note that request tracking middleware should be added as the very first middleware in pipeline, and Exception middleware should be added after error page and any other error handling middleware.
Now you have completed the server side configuration, which sends telemetry data from the server (back end) of your application. Now you can add client-side monitoring. This provides you with data on users, sessions, page views, and any exceptions or crashes that occur in the browser.
In _ViewImports.cshtml(if present), add injection.
Once you completed these configuration, you can run the application using “dotnet run”. And you can view the details in the azure portal.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub