c# - 应用洞察.NET |自定义指标不会显示在 Portal.azure.com 的指标下

标签 c# .net azure azure-application-insights

我的应用程序洞察采用“现收现付”模式运行。 标准绩效指标显示在门户中。 自定义指标不会显示在指标部分中。

我的环境。 运行普通 TCP 套接字的自定义 .NET Core 控制台应用程序。 (无 ASP.NET 核心) 使用

<PackageReference Include="Microsoft.ApplicationInsights" Version="2.7.2" />

Telemetry 类是使用默认构造函数构建的(并且没有 XML 配置文件)

自定义指标的创建方式如下

Telemetry.Client.GetMetric("number of clients").TrackValue(600.0);

问题: 我错过了什么或做错了什么,以致自定义指标没有显示? Azure 门户中的“指标”部分是否不是查找自定义指标的错误位置?

更新

示例代码也不会将任何自定义指标上传到 Azure。

        TelemetryClient client = new TelemetryClient();
        client.InstrumentationKey = "a valid key";
        client.GetMetric("test me").TrackValue(200);
        client.Flush();
        Thread.Sleep(5000);

最佳答案

此问题是由于检测 key 配置不正确造成的。

当使用GetMetric().TrackValue()时,我们应该使用这种方式来配置instrumentation key:

TelemetryConfiguration.Active.InstrumentationKey = "您的 key ";

我的代码如下:

  TelemetryClient client = new TelemetryClient();
  TelemetryConfiguration.Active.InstrumentationKey = "your key";  
  client.GetMetric("test33").TrackValue(100);  

  System.Threading.Thread.Sleep(1000*5);
  client.Flush();

  Console.WriteLine("Hello World!");
  Console.ReadLine();

然后在 Visual Studio 输出窗口中,您可以看到 ikey 显示在那里: enter image description here

然后进入azure门户->应用程序洞察->指标,您可以看到您的指标: enter image description here

为了进行比较,当您使用以下代码时:

client.InstrumentationKey = "a valid key";
client.GetMetric("test me").TrackValue(200);

执行后,在Visual Studio中,您可以看到输出窗口中没有ikey,因此不会将任何指标发送到azure门户: enter image description here

关于c# - 应用洞察.NET |自定义指标不会显示在 Portal.azure.com 的指标下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52552622/

相关文章:

c# - 在控制台应用程序中使用某些条件覆盖方法

c# - 在 PostSharp 的 OnMethodBoundaryAspect 中的 OnEntry 中获取 Controller 的基类成员

c# - 为什么 32 位 .NET 进程的引用类型的最小大小为 12 字节

azure - 更新应用程序设置时,Azure Functions 是否会引发 503 错误?

azure - 步骤引用版本 1.152.1 的 InvokeRESTAPI 任务,该任务对于给定作业目标无效

visual-studio-2012 - 将 .VDH 文件上传到 Azure 存储后出现问题

c# - DbQuery 与 IQueryable SQL 性能对比

c# - 模拟对象仍在调用服务

c# - 由字段初始化引起的有害代码爆炸的真实示例是什么?

c# - 如何干净地暂停一个线程,直到另一个线程完成或更改一个值