Search code examples
c#azure-application-insights

.NET 5 application insights is not showing my exception stack trace?


I have a .NET 5 web application and I have configured application insights. When an error is thrown in my application I can see it in the azure portal, but I don't see any stacktrace

enter image description here

I installed both nuget packages: enter image description here

In my startup:

    services.AddApplicationInsightsTelemetry();

I even tried to configure logging in my program.cs as described here

    Host.CreateDefaultBuilder(args)
            .ConfigureLogging(logging =>
            {
                logging.AddApplicationInsights();
                logging.AddFilter<ApplicationInsightsLoggerProvider>(string.Empty, LogLevel.Trace);
            })

What am I missing?


Solution

  • Okay so I'm still fiddling around with this a bit, but according to docs here "All exceptions handled by application still need to be tracked manually."

    Which means that if you write your own exception handlers, you still have to send the exception and stacktrace to application insights yourself.

    For example

    Either throw the original exception

    catch (Exception e)
    {
      throw;
    }
    

    Or send the exception yourself using Ilogger and LogError:

    catch (Exception e)
    {
        _logger.LogError(e, "message here");
        return BadRequest(e.ToString());
    }