【发布时间】:2020-02-08 00:26:52
【问题描述】:
无论我如何尝试,简单的 C# 控制台应用程序 (NetCORE) 中的 Application Insights 都不会获取 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>
密钥始终为空。
我已尝试将配置内容包含在内,并已尝试删除标记。我也尝试过以下代码:
var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault());
Console.WriteLine("Key=" + telemetryClient.InstrumentationKey);
我之前关于该主题的问题导致解决方案要求 ApplicationInsights.config 文件存在于项目文件夹中,以便调试应用程序洞察记录器正常工作。链接:Unable to get Application Insights to show debugging telemetry。一位用户指出,NetCORE 不再使用该配置文件,但我发现这很难相信,否则调试 Application Insights 中不会记录遥测数据 遥测。
它的文档没有在配置文件中提到 InstrumentationKey:https://docs.microsoft.com/en-us/azure/azure-monitor/app/configuration-with-applicationinsights-config#instrumentationkey
有没有办法只运行这两行代码并让它从配置文件中获取检测密钥,还是我必须在代码中手动设置它?
【问题讨论】:
标签: c# logging config azure-application-insights telemetry