正在创建log4net的日志,但剩余的空 [英] log4net log being created but remaining empty

查看:96
本文介绍了正在创建log4net的日志,但剩余的空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用 log4net的。当我火了它创建日志文件的应用程序,但不管多少次,我称之为 Log.Info(申请指南); 闲置。我已经研究了前两页,谷歌返回我的code似乎匹配的例子。

I'm attempting to use log4net. When I fire up the app it creates the log file, but no matter how many times I call Log.Info("Application Started"); it remains empty. I've researched the first two pages that google returns and my code seems to match all examples.

code:

[assembly: XmlConfigurator(Watch = true)]

namespace Generator
{
     public class Run
     {

       private static readonly log4net.ILog Log =
       log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public List<BILL_RUN> PerformBillRun()
        {
             XmlConfigurator.Configure();

             Log.Info("Application Started");
             var enabled = Log.IsInfoEnabled; //This is true
        }

     }

}

的app.config

app.config

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>

  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="log-files.txt" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="All" />
      <appender-ref ref="FileAppender" />
    </root>
  </log4net>

任何指针,以什么可能是错的?

Any pointers as to what may be wrong?

推荐答案

这总是发生在我身上......只要我张贴的问题。

This always happens to me...as soon as I post the question.

原来,我的&LT; configSections&GT;&LT; / configSections&GT; 标签并没有直接孩子&lt;结构&GT; 这意味着该配置将不会被拾起(我认为),因为这log4net的燕子所有异常仅表现出来,再进入我的应用程序。

It turns out my <configSections></configSections> tags weren't directly a child to <configuration> meaning that the config wouldn't be picked up (I assume), and because log4net swallows all exceptions this only manifested itself further into my app.

日志记录工作正常了。

这篇关于正在创建log4net的日志,但剩余的空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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