The Application Insights logging provider sends .NET application log events to an Azure Application Insights service, where logs and performance-related output can be collected and analyzed. It provides a cloud-based alternative to console, debug, event-source, and event-log providers. section 7.3.3 section 7.2.4
Using it with the MyBGList web API requires an Azure account and an Application Insights instance. Copy the instance connection string into application configuration before registering the provider. section 7.3.3
Configure the provider in four practical steps:
- Create an Application Insights instance through the Azure management experience. section 7.3.3
- Store the retrieved connection string under Azure:ApplicationInsights:ConnectionString. section 7.3.3
- Install Microsoft.Extensions.Logging.ApplicationInsights and Microsoft.ApplicationInsights.AspNetCore, both shown at version 2.21.0. section 7.3.3
- Register Application Insights through builder.Logging, optionally retaining simple console and debug providers alongside it. section 7.3.3 section 7.2.4
"Azure": {
"ApplicationInsights": {
"ConnectionString": "<INSERT_CONNECTION_STRING_HERE>" #1
}
}
Use the configuration listing as the required shape for the Azure connection string. section 7.3.3
> dotnet add package Microsoft.Extensions.Logging.ApplicationInsights --version 2.21.0
> dotnet add package Microsoft.ApplicationInsights.AspNetCore
--version 2.21.0
Use the package commands to add the Application Insights logging and ASP.NET Core integration libraries. section 7.3.3
builder.Logging
.ClearProviders()
.AddSimpleConsole()
.AddDebug()
.AddApplicationInsights( #1
telemetry => telemetry.ConnectionString =
builder
.Configuration["Azure:ApplicationInsights:ConnectionString"],
loggerOptions => { });
Use the logging-builder example to connect the configured connection string and keep console and debug output enabled. section 7.3.3
Verify telemetry
Run the web API and inspect Application Insights for application logs. The resulting entries are shown as TRACE event types, confirming that the provider is receiving application output. section 7.3.3
