Log4Net和Application Insights-没有数据通过 [英] Log4Net and Application Insights-no data is coming through

查看:97
本文介绍了Log4Net和Application Insights-没有数据通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的C#控制台应用程序中使用Log4Net,并且希望记录的事件也出现在Application Insights中.

I'm using Log4Net in my my C# console application and want the logged events to appear in Application Insights as well.

我添加了Application Insights和Application Insights Log4Net Appender.

I've added Application Insights as well as the Application Insights Log4Net Appender.

我已按照此处的说明进行操作: https ://jan-v.nl/post/using-application-insights-in-your-log4net-application ,没有运气.

I've followed the instructions here: https://jan-v.nl/post/using-application-insights-in-your-log4net-application with no luck.

Log4Net正常记录.但是,当我转到Application Insights仪表板时,会看到以下消息:应用程序中的应用程序中没有数据."

Log4Net is logging fine. However, when I go to the Application Insights dashboard, I see this: "THE APPLICATION HAS NO DATA IN APPLICATION INSIGHTS."

在我的主要cs文件的开头,我已经得到了:

At the beginning of my main cs file, I've got this:

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

最后是这个:

telemetryClient.Flush();

在我的app.config文件中,我有这个:

In my app.config file, I have this:

 <log4net>
    <root>
      <level value="INFO" />
      <appender-ref ref="FileAppender" />
      <appender-ref ref="aiAppender" />
    </root>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="C:\logs\logfile.txt" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
      </layout>
    </appender>
    <appender name="aiAppender" type="Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender, Microsoft.ApplicationInsights.Log4NetAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message%newline" />
      </layout>
    </appender>
  </log4net>

运行应用程序时,我会在输出窗口中看到这种情况:

When I run the application, I see this sort of thing in the output window:

Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Message","time":"2017-07-04T10:26:15.7741453Z","tags":{"ai.internal.sdkVersion":"log4net:2.2.0-220","ai.cloud.roleInstance":"xxx","ai.user.id":"AzureAD\\xxx"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"xxx","severityLevel":"Information","properties":{xxx"}}}}

我想念什么?

推荐答案

Log4Net AI追加器将不使用您创建的TelemtryClient.

Log4Net AI appender will not use the TelemtryClient you create.

像这样设置AI Instrumentation Key:

Set AI Instrumentation Key like this:

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

请参见 https://github.com/Microsoft/ApplicationInsights-dotnet-logging

这篇关于Log4Net和Application Insights-没有数据通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆