Log4net C#4.0 [(null)]输出 [英] Log4net C#4.0 [(null)] in output

查看:241
本文介绍了Log4net C#4.0 [(null)]输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用log4net登录.NET4.0时,我使用以下代码



LogManager声明:

  private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()。DeclaringType); 

在代码中使用时:

  log.Info(My info text); 

这会将以下内容输出到日志文件:

  2013-10-01 14:41:11,010 [3] INFO MyNamespace.MyClass [(null)]  - 我的信息文本



我想知道 [(null)] 是什么意思以及如何删除/更改?



这是我的配置文件:

 <?xml version =1.0 ?> 
< configuration>
< configSections>
< section name =log4nettype =log4net.Config.Log4NetConfigurationSectionHandler,Log4net/>
< / configSections>
< startup>
< supportedRuntime version =v4.0sku =。NETFramework,Version = v4.0/>
< / startup>
< log4net>
< root>
< level value =DEBUG/>
< appender-ref ref =LogFileAppender/>
< / root>
< appender name =LogFileAppendertype =log4net.Appender.RollingFileAppender>
< param name =Filevalue =log-file.txt/>
< param name =AppendToFilevalue =true/>
< rollingStyle value =Size/>
< maxSizeRollBackups value =10/>
< maximumFileSize value =10MB/>
< staticLogFileName value =true/>
< layout type =log4net.Layout.PatternLayout>
< param name =ConversionPatternvalue =%date [%thread]%-5级别%logger [%property {NDC}] - %message%newline/>
< / layout>
< / appender>
< / log4net>
< / configuration>


解决方案

停止它出现在日志中remove <$ c



这篇文章介绍了如何使用NDC,何时使用嵌套诊断上下文(NDC)?



简短调用静态方法 log4net.NDC.Push 来设置代码的上下文。

  log4net.NDC.Push(context)


$ b b

从这一点开始,输出日志消息将提供%property {NDC} 作为上下文


When I use log4net for logging in .NET4.0 I use the following code

LogManager declaration:

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

And when used in code:

log.Info("My info text");

This outputs the following to the log-file:

2013-10-01 14:41:11,010 [3] INFO  MyNamespace.MyClass [(null)] - My info text

I am wondering what the [(null)] means and how I can remove/change it?

This is my config-file:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="log-file.txt" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
  </log4net>
</configuration>

解决方案

To stop it appearing in the log remove [%property{NDC}] from the config file.

This post explains how to use NDC, When to use 'nested diagnostic context' (NDC)?

In short call the static method log4net.NDC.Push to set the context of the the code.

log4net.NDC.Push("context")

From that point forward outputting a log message will supply %property{NDC} as context.

这篇关于Log4net C#4.0 [(null)]输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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