Set up Application Insights for your ASP.NET website

This procedure configures your ASP.NET web app to send telemetry to the Azure Application Insights service. It works for ASP.NET apps that are hosted either in your own IIS server on-premises or in the Cloud. You get charts and a powerful query language that help you understand the performance of your app and how people are using it, plus automatic alerts on failures or performance issues. Many developers find these features great as they are, but you can also extend and customize the telemetry if you need to.

Setup takes just a few clicks in Visual Studio. You have the option to avoid charges by limiting the volume of telemetry. This allows you to experiment and debug, or to monitor a site with not many users. When you decide you want to go ahead and monitor your production site, it's easy to raise the limit later.

Prerequisites

To add Application Insights to your ASP.NET website, you need to:

  • Install Visual Studio 2017 with the following workloads:
    • ASP.NET and web development
    • Azure development

If you don't have an Azure subscription, create a free account before you begin.

Step 1: Add the Application Insights SDK

Right-click your web app name in the Solution Explorer, and choose Configure Application Insights

Screenshot of Solution Explorer, with Configure Application Insights highlighted

(Depending on your Application Insights SDK version you may be prompted to upgrade to the latest SDK release. If prompted, select Update SDK.)

Screenshot: A new version of the Microsoft Application Insights SDK is available. Update SDK highlighted

Application Insights Configuration screen:

Select Start Free.

Screenshot of Register your app with Application Insights page

If you want to set the resource group or the location where your data is stored, click Configure settings. Resource groups are used to control access to data. For example, if you have several apps that form part of the same system, you might put their Application Insights data in the same resource group.

Select Register.

Screenshot of Register your app with Application Insights page

Telemetry will be sent to the Azure portal, both during debugging and after you have published your app.

Note

If you don't want to send telemetry to the portal while you're debugging, just add the Application Insights SDK to your app but don't configure a resource in the portal. You are able to see telemetry in Visual Studio while you are debugging. Later, you can return to this configuration page, or you could wait until after you have deployed your app and switch on telemetry at run time.

Step 2: Run your app

Run your app with F5. Open different pages to generate some telemetry.

In Visual Studio, you will see a count of the events that have been logged.

Screenshot of Visual Studio. The Application Insights button shows during debugging.

Step 3: See your telemetry

You can see your telemetry either in Visual Studio or in the Application Insights web portal. Search telemetry in Visual Studio to help you debug your app. Monitor performance and usage in the web portal when your system is live.

See your telemetry in Visual Studio

In Visual Studio, to view Application Insights data. Select Solution Explorer > Connected Services > right-click Application Insights, and then click Search Live Telemetry.

In the Visual Studio Application Insights Search window, you will see the data from your application for telemetry generated in the server side of your app. Experiment with the filters, and click any event to see more detail.

Screenshot of the Data from debug session view in the Application Insights window.

Tip

If you don't see any data, make sure the time range is correct, and click the Search icon.

Learn more about Application Insights tools in Visual Studio.

See telemetry in web portal

You can also see telemetry in the Application Insights web portal (unless you chose to install only the SDK). The portal has more charts, analytic tools, and cross-component views than Visual Studio. The portal also provides alerts.

Open your Application Insights resource. Either sign into the Azure portal and find it there, or select Solution Explorer > Connected Services > right-click Application Insights > Open Application Insights Portal and let it take you there.

The portal opens on a view of the telemetry from your app.

Screenshot of Application Insights overview page

In the portal, click any tile or chart to see more detail.

Learn more about using Application Insights in the Azure portal.

Step 4: Publish your app

Publish your app to your IIS server or to Azure. Watch Live Metrics Stream to make sure everything is running smoothly.

Your telemetry builds up in the Application Insights portal, where you can monitor metrics, search your telemetry, and set up dashboards. You can also use the powerful Log Analytics query language to analyze usage and performance, or to find specific events.

You can also continue to analyze your telemetry in Visual Studio, with tools such as diagnostic search and trends.

Note

If your app sends enough telemetry to approach the throttling limits, automatic sampling switches on. Sampling reduces the quantity of telemetry sent from your app, while preserving correlated data for diagnostic purposes.

You're all set

Congratulations! You installed the Application Insights package in your app, and configured it to send telemetry to the Application Insights service on Azure.

Diagram of movement of telemetry

The Azure resource that receives your app's telemetry is identified by an instrumentation key. You'll find this key in the ApplicationInsights.config file.

Upgrade to future SDK versions

To upgrade to a new release of the SDK, open the NuGet package manager, and filter on installed packages. Select Microsoft.ApplicationInsights.Web, and choose Upgrade.

If you made any customizations to ApplicationInsights.config, save a copy of it before you upgrade. Then, merge your changes into the new version.

Video

Next steps

There are alternative topics to look at if you are interested in:

More telemetry

Analysis

Alerts

  • Availability tests: Create tests to make sure your site is visible on the web.
  • Smart diagnostics: These tests run automatically, so you don't have to do anything to set them up. They tell you if your app has an unusual rate of failed requests.
  • Metric alerts: Set these to warn you if a metric crosses a threshold. You can set them on custom metrics that you code into your app.

Automation