C# Application Insights不会从ApplicationInsights.config中拾取检测密钥

C# Application Insights不会从ApplicationInsights.config中拾取检测密钥,c#,logging,config,azure-application-insights,telemetry,C#,Logging,Config,Azure Application Insights,Telemetry,无论我怎么尝试,简单的C#控制台应用程序(NetCORE)中的应用程序洞察都不会获取InstrumentationKey。我正在使用以下代码: var telemetryClient = new TelemetryClient(); Console.WriteLine("Key=" + telemetryClient.InstrumentationKey); 以及以下ApplicationInsights.config文件: <ApplicationInsights xmlns="htt

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

var telemetryClient = new TelemetryClient();
Console.WriteLine("Key=" + telemetryClient.InstrumentationKey);
以及以下ApplicationInsights.config文件:

<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>
我之前关于该主题的问题产生了一个解决方案,该解决方案要求ApplicationInsights.config文件存在于项目文件夹中,以便调试应用程序洞察记录器正常工作。链接:。其中一位用户注意到NetCORE不再使用该配置文件,但我发现这很难相信,因为在调试应用程序洞察中没有记录遥测 遥测技术

其文档未在配置文件中提及InstrumentationKey:


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

对于.NET Core或ASP.NET Core项目,SDK不读取applicationinsights.config文件。 对于控制台应用程序,此处介绍了推荐的方法()。
在这些情况下,检测键在appsettings.json中指定。

我明白了。我觉得奇怪的是,它需要ApplicationInsights.config使用VS Application Insights日志记录工具跟踪遥测,以进行调试会话,如中所示。
var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault());
Console.WriteLine("Key=" + telemetryClient.InstrumentationKey);