无论我怎么尝试,简单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>密钥始终为空。
我已经尝试包装配置内容,并尝试删除标记。我也尝试过以下代码:
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
有没有办法只运行这两行代码,让它从配置文件中获取插装键,或者我必须在代码中手动设置它?
发布于 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中指定。
https://stackoverflow.com/questions/58324942
复制相似问题