Freigeben über

Azure Monitor Application Insights Quickstart for ASP.NET Core

This sample ASP.NET Core application was created with dotnet new razor. After that, the following changes were made:

  • The Application Insights SDK was added to the project with dotnet add package Microsoft.ApplicationInsights.AspNetCore --version 2.17.0.
  • A configuration value for ApplicationInsights:InstrumentationKey was added to appsettings.json.
  • services.AddApplicationInsightsTelemetry(); was added to the ConfigureServices method of Startup.cs.
  • @inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet was added to Pages/_ViewImports.cshtml.
  • @Html.Raw(JavaScriptSnippet.FullScript) was added to the <head> element in Pages/Shared/_Layout.cshtml.

Prerequisites

Prepare to run the sample

Replace the placeholder ApplicationInsights:InstrumentationKey value in appsettings.json with your actual instrumentation key.

Run the sample

dotnet run

As you use the app, telemetry will be ingested to Application Insights within a few minutes. You can verify the connection using Live Metrics.