RollingFileAppender无法正常工作

RollingFileAppender无法正常工作

本文介绍了Log4net RollingFileAppender无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Log4net在Windows应用程序中运行正常,但是每当我在Windows服务中使用相同的配置时,Rollingappender均不起作用
.
所有日志都写在同一文件中.如果您对此行为有所了解,请回复.

查找配置设置:

Hi,

Log4net is working fine in my windows application but whenever I use same config in Windows service, Rollingappender does not work
.
All logs are written in same file. If you know some thing about this behavior then please reply.

Find the config setting:

<log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="Logs/Notification.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="-dd-MMM-yy" />
      <!--Roll every Day-->
      <maxSizeRollBackups value="-1" />
      <!--Infinite backups-->
      <maximumFileSize value="2MB" />
      <!--Maximum size of 1 file-->
      <layout type="log4net.Layout.PatternLayout">
        <!--http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html-->
        <conversionPattern value="%date{dd-MMM-yy, HH:mm:ss} - %5level [%thread] - %message%newline " />
      </layout>
    </appender>
    <root>
      <!-- Ascending Priority: Debug,Info,Warn,Error,Fatal,ALL -->
      <priority value="ALL" />
      <appender-ref ref="RollingLogFileAppender" />
    </root>




问候,
Jitendra Zaa




Regards,
Jitendra Zaa

推荐答案

log4net.Config.XmlConfigurator.ConfigureAndWatch(
  new System.IO.FileInfo("log4net.config"));



例如或DOMConfigurator(不建议使用?)程序集属性



e.g or the DOMConfigurator (deprecated?) assembly attribute

// Log4Net watch XML attribute
[assembly: log4net.Config.DOMConfigurator(Watch=true)] 




当我的附加程序不起作用时,通常这是我忘记的步骤!




When my appenders aren''t working, it''s normally this step I''ve forgotten!


这篇关于Log4net RollingFileAppender无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:42