【问题标题】:Setting up Application Insights on a console app在控制台应用程序上设置 Application Insights
【发布时间】:2017-07-04 09:13:19
【问题描述】:

我在控制台应用程序上运行了 Log4Net,并且希望将日志事件转到 Application Insights。

我无法通过右键单击我的项目来添加 AI - 它没有显示为选项。

我已经通过 NuGet 安装了 AI SDK,并且能够创建遥测客户端,但不知道在哪里添加检测密钥。

This教程说:

在您的代码中设置检测密钥:

TelemetryConfiguration.Active.InstrumentationKey = " your key ";

或在 ApplicationInsights.config 中(如果您安装了标准遥测包之一):

<InstrumentationKey>your key</InstrumentationKey>

我没有 ApplicationInsights.config 文件,因为我无法将 AI 添加到项目中。如果我像这样在实例化遥测客户端时添加密钥,它会起作用吗?

var telemetryClient = new TelemetryClient { InstrumentationKey = ConfigurationManager.AppSettings["applicationInsights"] };

【问题讨论】:

    标签: log4net azure-application-insights


    【解决方案1】:

    你最后的建议可能会奏效。你也可以这样做:

    TelemetryConfiguration.Active.InstrumentationKey =  ConfigurationManager.AppSettings["applicationInsights"];
    

    【讨论】:

    • 程序开始的某个地方,在主目录中。或者在 init 方法中。
    猜你喜欢
    • 2021-12-22
    • 2019-02-12
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多