I'm working on a ASP.NET Core MVC application and would like to use Serilog both for logging trace messages (Information) and Exceptions to Application Insight. The configuration code (from Program.cs) is provided below.
builder.Host.UseSerilog((context, services, configuration) => configuration .MinimumLevel.Information()
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.ApplicationInsights(appInsightConnection, TelemetryConverter.Traces, LogEventLevel.Information);
When I call Log.Error(ex, ex.Message) in a try...catch block, it does not log the exception to Application Insights. Please note anything I send using Log.Infomation gets logged in Application Insights.
My understanding is if the logger is set to handle a minimum level (in my case, Information), anything above that level should be logged in App Insights but unfortunately that's not happening in my case.
Any help would be greatly appreciated. Thank you
I tried setting MinimumLevel to Information when configuring Serilog and was expecting anything above the level of Information (which includes Exceptions) would be sent to Application Insights but only Log.Information seems to get logged in AppInsights.
What I have observed is as follows:
When LogEventLevel is set to Information in .WriteTo.ApplicationInsights(), then anything that's logged using Log.Information is sent to ApplicationInsight but Exceptions are not sent.
When
LogEventLevelis set to Error, thenLog.Exceptionlogs the exception in Application Insight butLog.Informationfails to log the trace messages in Application Insight.