应用程序洞察使应用程序在启动时冻结

Application insights make the app freeze on startup

我正在使用 Template10 为 Windows 10 构建一个 UWP 应用程序。我想使用 MS Application Insights。在我的项目中,我引用了:Microsoft.ApplicationInsights (2.0.0)、Microsoft.ApplicationInsights.PersistenceChannel (1.2.3)、Microsoft.ApplicationInsights.WindowsApps (1.1.1)。在 App 构造函数中,我必须使用以下代码:

public App()
{
    WindowsAppInitializer.InitializeAsync();

    InitializeComponent();
    SplashFactory = (e) => new Views.Splash(e);

    #region App settings

    _settings = SettingsService.Instance;
    RequestedTheme = _settings.AppTheme;
    CacheMaxDuration = _settings.CacheMaxDuration;
    ShowShellBackButton = _settings.UseShellBackButton;

    #endregion
}

我还从 Azure 添加了正确的 InstrumentationKey 到 ApplicationInsights.config,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
    <InstrumentationKey>my-key</InstrumentationKey>
</ApplicationInsights>

但是,当我启动我的应用程序时,它只是挂在应用程序徽标上。当我评论 WindowsAppInitializer.InitializeAsync(); 行时,应用程序正常运行。

我已尝试从项目中删除和读取提到的引用,删除并重新安装 Visual Studio 的 Application Insights Tools,但没有成功。

当我创建一个新的空白应用程序(通用 Windows)时,Visual Studio 会自动设置 Application Insights 并按预期工作。但是我无法让它与我现有的项目一起使用。

请帮忙。

有关在 UWP 应用程序中使用 Application Insights 的故事已被弃用,取而代之的是 HockeyApp,并且 UWP 上的 AI 2.0.0 存在一个已知问题。

https://github.com/Microsoft/ApplicationInsights-dotnet/issues/210

刚才我遇到了完全相同的问题,我终于成功了。因此,将 project.json 中的依赖项更改为如下所示:

"dependencies": {
    ...
    "Microsoft.ApplicationInsights": "1.0.0",
    "Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
    "Microsoft.ApplicationInsights.WindowsApps": "1.0.0"
},

如果这没有帮助,我还建议将检测密钥添加到 WindowsAppInitializer:

WindowsAppInitializer.InitializeAsync("YOURKEY");