asp.net-core - .NET 核心 3.1 ApplicationInsight IntrumentKey null
问题描述
在 .net core 3.1 Blazor App 中,我的 Instrument Key 始终为空。我添加了以下包
Microsoft.ApplicationInsights.AspNetCore 2.14.0-beta5
在 startup.cs 中,我添加以下行
services.AddApplicationInsightsTelemetry();
我什至尝试通过选项对仪器键进行硬编码,但也没有运气。
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions
= new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
aiOptions.InstrumentationKey = Configuration.GetSection("ApplicationInsights:InstrumentationKey").Value;
services.AddApplicationInsightsTelemetry(options);
在 appsetting.json 中,我定义了 applicaiton Insight
"ApplicationInsights": {
"InstrumentationKey": "XXXXXXX-4f59-4580-a96a-XXXXXXX"
}
在我的 Blazor 页面中,我注入了依赖项
@inject Microsoft.ApplicationInsights.TelemetryClient telemetryClient;
现在当我搜索 telemetryClient.InstrumentationKey
它是空的。
我错过了什么?
解决方案
有点奇怪。我也尝试通过调用 telemetryClient.InstrumentationKey 来查看密钥,但就像你说的那样它是空的。但是,当我尝试使用 .TrackEvent 跟踪某些内容时,它会记录下来。
例如;
_telemetryClient.TrackEvent("BlazorAppSampleEvent", new Dictionary<string, string>() { { "Hello from", "Blazor App" } });
对我来说听起来很有趣,如果我有新的东西,我会再花几分钟时间在这里更新。
顺便说一句,您知道,Microsoft.ApplicationInsights.AspNetCore 2.14.0 是公开可用的,因此您可以将它从 beta-5 升级到公开版本。
https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.14.0/
推荐阅读
- c# - 在Task返回函数中调用Task.Result是否阻塞调用线程
- c - %g printf 说明符究竟是什么意思?
- c - 在 C 中制作 getline()
- dart - 异步任务有没有结束
- php - 如何修复未填充在 HTML 表中的 JSON 数据
- android - 传递 MoPub 关键字的关键参数是什么?
- python - 收到错误消息:ModuleNotFoundError: No module named 'matplotlib.artist'
- python - Plotly - 如何在单个图中复制相同的直方图
- php - 单击“重置”按钮时,并非重置所有搜索字段
- excel - 为什么我的号码转文本代码不起作用?