Hi Neeraj - Thanks for resending the question.
Here are the steps and configurations you can check to ensure that Information level logs are captured:
Verify Logging Configuration: Ensure that your logging configuration in appsettings.json
or environment variables is correctly set to capture Information level logs. Here is an example of how your appsettings.json
might look:
{
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
},
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Configure Application Insights Logging: Make sure you have added the Application Insights logging provider correctly in your Program.cs
file. Here is an example:
using Microsoft.Extensions.Logging.ApplicationInsights;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddApplicationInsightsTelemetry();
// Configure logging
builder.Logging.AddApplicationInsights(
configureTelemetryConfiguration: (config) => config.ConnectionString = builder.Configuration.GetConnectionString("ApplicationInsights"),
configureApplicationInsightsLoggerOptions: (options) => { }
);
builder.Logging.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Information);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
Check Environment Variables: Ensure that there are no environment variables overriding your logging configuration. You can print out the current log level to verify:
var logLevel = builder.Configuration["Logging:ApplicationInsights:LogLevel:Default"];
Console.WriteLine($"Current LogLevel from config: {logLevel}");
Update NuGet Packages: Ensure that you are using the latest version of the Microsoft.ApplicationInsights.AspNetCore
package. Sometimes, issues can arise from using outdated packages.
Custom Telemetry Processor: If you have a custom telemetry processor or filter, ensure that it is not filtering out Information level logs.
By following these steps, you should be able to ensure that Information level logs are captured and sent to Application Insights. If the issue persists, you might want to check the official documentation for any additional configuration details or updates