这个log4net实现我在做什么错? [英] What am I doing wrong with this log4net implementation?

查看:151
本文介绍了这个log4net实现我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与其他许多人一样,我正在尝试在我的C#.net应用程序中实现Log4net,但我无法使其正常工作.我已经进行了很多搜索(包括在此站点上进行搜索),并尝试了许多不同的解决方案,但对我来说仍然没有任何效果.因此,一个简单的问题是:我在做什么错??

Like many others, I'm trying to implement Log4net into my C#.net application and I just can't get it to work for me. I've done a lot of searching (including on this site) and have tried many different solutions but nothing has worked for me yet. So the simple question: What am I doing wrong???

Assembly.cs包含以下行.

Assembly.cs contains the following line.

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

App.config包含以下内容.

App.config contains the following.

<configSections> 
  <section name="log4net" 
           type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> 
</configSections>
<log4net> 
  <root> 
    <level value="ALL"/> 
    <appender-ref value="RollingFileAppender"/> 
    <appender-ref value="ConsoleAppender"/> 
  </root>
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">  
    <param name="File" value="C:\Temp\Minion.log" />
    <appendToFile value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="5" />
    <maximumFileSize value="10MB" />
    <staticLogFileName value="true" />
    <layout type="log4net.Layout.PatternLayout">  
      <conversionPattern value="%date{Y-m-d H:i:s.u} | %thread | %method | %level | %message%newline" />
    </layout>
  </appender>
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
    <layout type="log4net.Layout.PatternLayout">
      <param name="Header" value="[Header]\r\n" />
      <param name="Footer" value="[Footer]\r\n" />
      <param name="ConversionPattern" value="%date{Y-m-d H:i:s.u} | %thread | %method | %level | %message%newline" />
    </layout>
  </appender>
</log4net>

我的代码在课程开始时包含以下内容.

My code contains the following at the start of the class.

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

这些在主功能开始时进行测试.

And these tests at the start of the main function.

logger.Debug("test1");
logger.Info("test2");
logger.Warn("test3");
logger.Error("test4");
logger.Fatal("test5");

提示在log4net初始化期间导致以下错误.

A tip led to the following errors during log4net initializaiton.

log4net:ERROR XmlHierarchyConfigurator: No appender named [] could be found.
log4net:ERROR Appender named [] not found.
log4net:ERROR XmlHierarchyConfigurator: No appender named [] could be found.
log4net:ERROR Appender named [] not found.

推荐答案

更改此内容:

<appender-ref value="RollingFileAppender"/> 
<appender-ref value="ConsoleAppender"/> 

对此:

<appender-ref ref="RollingFileAppender"/> 
<appender-ref ref="ConsoleAppender"/> 

看看它是否会更好地合作.

And see if it won't cooperate better.

这篇关于这个log4net实现我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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