【问题标题】:Application Insights does not pickup Instrumentation Key from ApplicationInsights.configApplication Insights 不会从 ApplicationInsights.config 获取检测密钥
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 我明白了。我觉得很奇怪,它需要 ApplicationInsights.config 使用 VS Application Insights 日志记录工具来跟踪遥测以进行调试会话,如 stackoverflow.com/questions/58307327/… 所示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 2019-01-13
    • 1970-01-01
    相关资源
    最近更新 更多