首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序洞察不能从ApplicationInsights.config获取工具密钥

应用程序洞察不能从ApplicationInsights.config获取工具密钥
EN

Stack Overflow用户
提问于 2019-10-10 22:10:51
回答 1查看 2.6K关注 0票数 3

无论我怎么尝试,简单C#控制台应用程序(NetCORE)中的应用程序洞察都不会获得InstrumentationKey。我使用了以下代码:

代码语言:javascript
复制
var telemetryClient = new TelemetryClient();
Console.WriteLine("Key=" + telemetryClient.InstrumentationKey);

和以下ApplicationInsights.config文件:

代码语言:javascript
复制
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
  <InstrumentationKey>1234</InstrumentationKey>
  <!--https://docs.microsoft.com/en-us/azure/azure-monitor/app/configuration-with-applicationinsights-config#instrumentationkey-->
</ApplicationInsights>

密钥始终为空。

我已经尝试包装配置内容,并尝试删除标记。我也尝试过以下代码:

代码语言:javascript
复制
var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault());
Console.WriteLine("Key=" + telemetryClient.InstrumentationKey);

我之前关于这个主题的问题导致了一个解决方案,该解决方案要求ApplicationInsights.config文件存在于项目文件夹中,以便调试应用程序洞察记录器能够正常工作。链接:Unable to get Application Insights to show debugging telemetry。其中一个用户注意到NetCORE不再使用该配置文件,但我发现很难相信,否则调试应用程序洞察遥测中将不会记录遥测。

它的文档没有在配置文件中提到InstrumentationKey:https://docs.microsoft.com/en-us/azure/azure-monitor/app/configuration-with-applicationinsights-config#instrumentationkey

有没有办法只运行这两行代码,让它从配置文件中获取插装键,或者我必须在代码中手动设置它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-11 00:12:31

对于.NET核心或ASP.NET核心项目,SDK不读取applicationinsights.config文件。对于控制台应用程序,推荐的方法记录在此处(https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service#net-corenet-framework-console-application)。在这些情况下,检测密钥在appsettings.json中指定。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58324942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档