Application Insights: How to track crashes in Desktop (WPF) applications?

1.3k views Asked by At

I'm using Application Insights for a WPF Application. Tracking of PageViews and custom events is working.

Now I would like to track crashes. My idea was to:

private void AppDispatcherUnhandledException(object sender, 
    DispatcherUnhandledExceptionEventArgs e)
{
    telemetryClient.TrackException(e.Exception);
    telemetryClient.Flush();
}

The code is called when a unhandled exception occurs but it is not shown as "Crash" in the Application Insights portal. I have read somewhere that TrackException does not count as "Crash" when the application does not really crash.

Desktop (e.g. WPF) applications must use the low level API of Application Insights. I have not found a way to tell Application Insights that the WPF Application is crashing.

How could I do that?

1

There are 1 answers

1
Ameya Gholkar On BEST ANSWER

For WPF applications, there is no inherent support for capturing crashes. Your statement "The code is called when a unhandled exception occurs but it is not shown as "Crash" in the Application Insights portal. I have read somewhere that TrackException does not count as "Crash" when the application does not really crash." - is true.
Here is the documentation describing it.

If you still want to treat the exceptions that you are handling to be treated as crashes, the one way that you can do that is by treating the tracked exception as unhandled.

Here is how -

        var exceptionTelemetry = new Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry(new Exception());
        exceptionTelemetry.HandledAt = Microsoft.ApplicationInsights.DataContracts.ExceptionHandledAt.Unhandled;
        telemetryClient.TrackException(exceptionTelemetry);