1

Some general setup of my system:

  • Windows x64
  • .net 3.1
  • AspNet.Core
  • Serilog + AppInsights writer

Recently, we started to observe many trace logs like below. I think something went wrong when we try to write log into AppInsights. But we can see our logs. It seems we have everything we wanted logging into AppInsights correctly. But we also have this unwanted trace message logged in as well, and there are a lot of them.

This trace message happens on my local machine, in our Azure AKS environment. But the stack trace is too short to help locating the origin of the error.

AI (Internal): [Microsoft-ApplicationInsights-Core] [msg=Log Error];[msg=Exception while initializing Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.ClientIpHeaderTelemetryInitializer, exception message - System.ObjectDisposedException: Request has finished and HttpContext disposed.
Object name: 'HttpContext'.
   at Microsoft.AspNetCore.Http.DefaultHttpContext.ThrowContextDisposed()
   at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Features()
   at Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.TelemetryInitializerBase.Initialize(ITelemetry telemetry)
   at Microsoft.ApplicationInsights.TelemetryClient.Initialize(ITelemetry telemetry)]
David S.
  • 10,578
  • 12
  • 62
  • 104

1 Answers1

-1

I tried to create an environment, with Asp.net core application & .net3.1 for track down the logs (Request, exceptions, users, failure, trace etc.)

Here are the steps i followed : Added application insight telemetry to my application and install the NuGet package Microsoft.ApplicationInsights.AspNetcore

enter image description here

And in startup.cs under services.AddControllersWithViews(); add

services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]);

enter image description here

After deploy the app to azure and for tracing the logs go to my created Application insights> Transaction search>view data ,Where we can see all of our logs as below also to identify if there is any error occurs.

enter image description here

Also we can download all our logs and track down for the application using kudu-console. Go to App service>Advance tools>Go

enter image description here

enter image description here

For more information please refer the below links:

.MS DOC | Explore .NET/.NET Core and Python trace logs in Application Insights

.SO Thread | Application Insights not showing stack trace for errors

.Blog| Using Azure Application Insights For Exception Logging In C#

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15