I have tried to Integrate Application Insights
in .NET Core6
Web App using the Application Insights Connection String
and able to see the traces without any warnings.
You are writing the code inStartup.cs
, .NET 6
doesn't require Startup.cs
file, the code can be configured within the Program.cs
file.
In .NET 6 both Program.cs
and Startup.cs
configurations are unified into a single file Program.cs
.
My appsettings.json
{
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Error"
}
},
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=****;IngestionEndpoint=https://*****.in.applicationinsights.azure.com/;LiveEndpoint=https://****.livediagnostics.monitor.azure.com/"
}
}
Program.cs
var builder = WebApplication.CreateBuilder(args);
var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions
{
EnableDependencyTrackingTelemetryModule = false,
};
builder.Services.AddApplicationInsightsTelemetry(aiOptions);
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
Traces for MVC
public IActionResult Index()
{
_logger.LogInformation("Log Information from Controller.");
_logger.LogDebug("Debug Message from the Controller.");
_logger.LogWarning("Log Warning.");
_logger.LogError("Log Error.");
return View();
}
Traces for Web App
var app = builder.Build();
ILogger logger = app.Logger;
logger.LogInformation("Test logs");
logger.LogWarning("Iam a Warning Message");
Traces for MVC App

Traces for Web App
