首页 > 解决方案 > .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 它是空的。

我错过了什么?

标签: asp.net-coreazure-application-insightsblazor-server-side

解决方案


有点奇怪。我也尝试通过调用 telemetryClient.InstrumentationKey 来查看密钥,但就像你说的那样它是空的。但是,当我尝试使用 .TrackEvent 跟踪某些内容时,它会记录下来。

例如;

_telemetryClient.TrackEvent("BlazorAppSampleEvent", new Dictionary<string, string>() { { "Hello from", "Blazor App" } });

App Insight 实时示例

对我来说听起来很有趣,如果我有新的东西,我会再花几分钟时间在这里更新。

顺便说一句,您知道,Microsoft.ApplicationInsights.AspNetCore 2.14.0 是公开可用的,因此您可以将它从 beta-5 升级到公开版本。

https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.14.0/

Microsoft.ApplicationInsights.AspNetCore 2.14.0


推荐阅读