从后台任务报告时,为什么 Application Insights 数据不显示在我的仪表板中?

Why won't Application Insights data show in my dashboard when reported from a Background Task?

我在后台任务运行时记录了 MS App Insights 数据。然而,虽然我在调试代码时没有收到来自 AI 的异常,但我的仪表板中没有显示任何内容,正如我所期望的那样。来自同一会话(在主应用程序中,而不是后台任务)的所有其他遥测记录都很好。

我正在 Windows 10 Mobile with AI pkg v1.2.3

上尝试此操作

您可能需要定期或在后台任务退出之前 .flush() TelemetryClient。

原来密钥是利用新的 PersistenceChannel 作为我的遥测通道,如下所示:

TelemetryConfiguration.Active.TelemetryChannel = new PersistenceChannel();

然后在我的背景任务中:

var c = new TelemetryClient() { InstrumentationKey = <my app insights key> };
c.TrackEvent(evt);
c.Flush();

documentation for PersistenceChannel 展示了它如何执行 AI 以前自动执行的操作:将结果缓存到本地存储,直到它们能够被发送到 AI 服务。

这使我的后台任务能够启动并缓存其分析,直到用户启动应用程序(因此 AI 对象可以访问后端服务)或 bg 任务有足够的时间和精力去做它本身。