Application Insights:如何跟踪桌面 (WPF) 应用程序中的崩溃?

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

我正在为 WPF 应用程序使用 Application Insights。正在跟踪网页浏览量和自定义事件。

现在我想跟踪崩溃。我的想法是:

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

当发生未处理的异常时调用该代码,但它在 Application Insights 门户中未显示为 "Crash"。我在某处读到,当应用程序没有真正崩溃时,TrackException 不算作 "Crash"。

桌面(例如 WPF)应用程序必须使用 Application Insights 的低级别 API。我还没有找到一种方法来告诉 Application Insights WPF 应用程序正在崩溃。

我该怎么做?

对于 WPF 应用程序,没有对捕获崩溃的固有支持。您在 Application Insights 门户中的声明 "The code is called when a unhandled exception occurs but it is not shown as "Crash”。我在某处读到,当应用程序没有真正崩溃时,TrackException 不算作 "Crash"。” - 是真的。
Here 是描述它的文档。

如果您仍想将正在处理的异常视为崩溃,您可以这样做的一种方法是将跟踪的异常视为未处理。

方法如下 -

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