Monitoring with Azure Application Insights
Creating an Azure Container Apps environment (starting with Chapter 6) also creates an Azure Log Analytics resource. In this chapter, we add an Azure Application Insights resource, and add a Log Analytics respource explicitly to the app model. Log Analytics and Application Insights are both part of the Azure Monitor service.
Log Analytics is used to monitor the amount of log data created and the cost associated and gives reasons when there is a higher-than-expected usage. Application Insights has a focus on application telemetry data and user data.
Configuring the .NET Aspire host for Application Insights
To add Application Insights, add the NuGet package Aspire.Hosting.Azure.ApplicationInsights
, and update the Program.cs
file of the .NET Aspire AppHost
project:
Codebreaker.AppHost/Program.cs
var builder = DistributedApplication.CreateBuilder(args); // code removed for brevity var logs = builder.AddAzureLogAnalyticsWorkspace...