3

I'm setting up a pretty simple ASP.Net Core (2.2) MVC Web App. I want to be able to see any application errors (500s) and what caused them so it seems like Application Insights is the place to look.

If I go into Application Insights / Failures (Operations Tab - see screenshot below), I'm able to see a graph/count of all the 500 errors. I can click on "DRILL INTO" button and see a lof of the details (Event Time, Request Name, etc...) but cannot seem to get any details on the actual cause of the error / line number.

failures

Basically, I have the exact same problem as this person: Azure Monitor / Application Insights not showing stack trace for errors (my screenshots look identical).

When I drill down to the exception details, I get something like this:

myexception

I'm want to get something like this:

Exception Section

I did see info on adding Application Insights via Nuget to my solution and putting

 services.AddApplicationInsightsTelemetry();

into the Startup/ConfigureServices method.

I also see that you can look at Kudu logs, etc... but I really want this all to be easily accessible in Application Insights.

Any suggestions?

Mike Smith
  • 618
  • 10
  • 27

2 Answers2

3

OK - I think I solved my own problem. Turns out I had added Serilog a while back (sort of forgot about that) and it was capturing all the errors before getting to AI. When I removed the Serilog configuration code from Program.cs and Startup.cs, the application exceptions started showing up in Application Insights / Failures along with the full Call Stack. Thanks for your suggestions!

Mike Smith
  • 618
  • 10
  • 27
  • You can use the Serlog Sink for Application Insights so you can have both working at the same time: https://github.com/serilog/serilog-sinks-applicationinsights – JoanComasFdz Feb 03 '21 at 14:48
0

A 500 Internal server error suggests you are looking for the stack trace to identify what went wrong and where. No code has been provided in your example but you will need to surround your code with a try catch and then log the exception to get the stack trace or you can use the TelemetryClient as below:

var telemetry = new TelemetryClient();
...
try
{ ...
}
catch (Exception ex)
{
   // Set up some properties:
   var properties = new Dictionary <string, string>
     {{"Game", currentGame.Name}};

   var measurements = new Dictionary <string, double>
     {{"Users", currentGame.Users.Count}};

   // Send the exception telemetry:
   telemetry.TrackException(ex, properties, measurements);
}

Further information can be found at Microsoft

eVolve
  • 1,340
  • 1
  • 11
  • 30
  • Thanks for the suggestion but is this really the only way to get a stack trace into App Insights? It seems to be a method for tracking other telemetry items associated with the transaction (such as current game and current user count). I know that if you turn off custom errors you can see the line number and exception description on the server -is there not a way to view that in Application Insights without adding code to each try/catch statement? – Mike Smith Dec 30 '19 at 00:29
  • There is this statement in the doc which seems to indicate it's automatically done: "Starting with Application Insights Web SDK version 2.6 (beta3 and later), Application Insights collects unhandled exceptions thrown in the MVC 5+ controllers methods automatically. If you have previously added a custom handler to track such exceptions (as described in following examples), you may remove it to prevent double tracking of exceptions." (I'm using Application Insights Web v 2.12) – Mike Smith Dec 30 '19 at 00:47