You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WinUI应用商店审核启动崩溃,Application Insights日志采集失败

WinUI应用商店启动崩溃排查:Application Insights无法正常工作问题

我开发的WinUI应用已在微软商店正常发布数月,近一周却多次因「启动时崩溃」被拒,且未获得额外反馈。应用本地运行正常且通过认证,想通过日志排查问题,但Application Insights无法正常工作,调用日志代码后无数据显示。

当前配置与代码

依赖注入配置代码

this.serviceProvider = serviceCollection
    .AddSingleton(this.configuration)
    .AddLogging(lb => lb.AddApplicationInsights(
        tc =>
        {
            tc.DisableTelemetry = this.configuration.GetValue("ApplicationInsights:DisableTelemetry", true);
            tc.ConnectionString = this.configuration.GetValue("ApplicationInsights:ConnectionString", Guid.Empty.ToString());
        },
        ailo => { }))
    .AddLocalization()
    .BuildServiceProvider();

配置文件内容

{
  "ApplicationInsights": {
    "DisableTelemetry":  true,
    "ConnectionString": "InstrumentationKey=20fafaa0-aeef-4ce9-927d-47b9df47e479"
  }
}

日志调用代码

// Log a progress indication message.
ILogger logger = this.serviceProvider.GetRequiredService<ILogger<App>>();
logger.LogError("{message}", $"Launching {packageInfo.Name}, {packageInfo.Version}.");

排查与修复步骤

  • 关闭Telemetry禁用开关:配置里DisableTelemetry设为true会直接阻断所有遥测上报,必须改为false才能让Application Insights生效。
  • 完善ConnectionString:当前配置仅包含InstrumentationKey,建议使用Azure门户中Application Insights资源提供的完整ConnectionString(格式示例:InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/;LiveEndpoint=https://xxx.livediagnostics.monitor.azure.com/),确保数据能正确发送到Azure服务器。
  • 确认日志级别配置:默认情况下,Application Insights可能只收集Warning及以上级别的日志,但需确保日志构建器配置了正确的最小级别。可在AddLogging中添加lb.SetMinimumLevel(LogLevel.Error);(按需调整级别),保证LogError能被捕获。
  • 调整WinUI初始化顺序:WinUI应用启动阶段的初始化顺序可能影响日志收集,建议在App.xaml.cs的OnLaunched方法中尽早完成Application Insights初始化,同时检查configuration对象是否正确读取到配置值(可通过本地调试输出确认)。
  • 本地验证上报:修改配置后本地运行应用,触发日志上报,然后到Azure门户的Application Insights中查询traces表,确认是否有数据。若仍无数据,可添加tc.EnableDebugLogger = true;启用调试模式,查看输出窗口的调试信息排查发送失败原因。
  • 商店版本权限与配置检查:提交到商店的版本必须确保DisableTelemetry为false且ConnectionString正确,同时检查应用清单是否添加了internetClient网络权限,否则无法向Azure发送日志数据。

内容的提问来源于stack exchange,提问作者user365462

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 13:46:30