火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

log4net 的 DailyRollingFileAppender 配置方式

Posted on 2007-08-08 09:21  剑廿三  阅读(3069)  评论(0编辑  收藏  举报
http://www.l4ndash.com/Log4NetMailArchive/tabid/70/forumid/1/postid/15396/view/topic/Default.aspx

Pinto, Antonio Joaquim

10/01/2004 3:43 PM Alert 
I´m using the latest version of log4net, with MS .NET Window Aplication, that is always running. I need one time every day to backup the log files from older days, but i can´t do it, because all the files are being used by the aplication ( System.IO.IOException - The process cannot access the file because it is being used by another process. ) when trying to move the old files to a backup directory. How can i release the files that aren´t already being used?
 
Thanks,
Antonio Pinto.
 
Dag Christensen

10/01/2004 3:50 PM Alert 

Do you use RollingFileAppender for your logging? I'm using this setup which does not lock any of the "rolled" backup files.

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="log.txt" />
        <param name="CountDirection" value="1" />
        <param name="AppendToFile" value="true" />
        <param name="MaxSizeRollBackups" value="3" />
        <param name="MaximumFileSize" value="5MB" />
        <param name="RollingStyle" value="Size" />
        <param name="StaticLogFileName" value="true" />
        <layout type="log4net.Layout.PatternLayout">
                <param name="ConversionPattern" value="%d{dd.MM.yy HH:mm:ss} [%t] %-5p %c [%x] %m%n" />
        </layout>
</appender>

Dag

Pinto, Antonio Joaquim

10/01/2004 3:58 PM Alert 

I´m using this one:

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="log.txt" />
  <appendToFile value="true" />
  <maximumFileSize value="1MB" />
  <maxSizeRollBackups value="-1" />
  <param name="RollingStyle" value="Composite" />
  <param name="StaticLogFileName" value="false" />
  <param name="CountDirection" value="1" />
  <param name="DatePattern" value=".yyyMMdd.\S\U\C" />
  <layout type="log4net.Layout.PatternLayout">
   <conversionPattern value="%-5p|%d|Thread:%-4t|%c %x|%m%n" />
  </layout>
 </appender>

I see some diferences, but where is the problem? The maxSizeRollBackups? The RollingStyle?

Thanks.

Mario Gutierrez

10/01/2004 7:13 PM Alert 
Use RollingFileAppender to break up the log into manageable chunks. Then make backups of the rolled files. I wonder if there is DailyRollingFileAppender like the one for log4j which creates a new log ever day.
 
Mario Gutierrez

10/01/2004 11:14 PM Alert 
RollingFileAppender can do a daily log.  For example, to have it create a daily log file like this log4net-2004.10.01
 
  <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
   <param name="File" value="log4net" />
   <param name="AppendToFile" value="true"/>
   <param name="DatePattern" value="-yyyy.MM.dd"/>   
   <param name="RollingStyle" value="Date"/>
   <param name="StaticLogFileName" value="false"/>
   <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="## %d %t %-5p %c %x %n%m%n"/>
   </layout>
  </appender>
Nicko Cadell

10/06/2004 5:34 PM Alert 

Antonio,

Which files are you unable to move? Are they the files with today's date? Yesterdays date?
When you try to move yesterdays files is there a new logfile for today?

The RollingFileAppender will only roll the log file when a message is logged, e.g. if will roll the file when it receives the first message to log in a day. If no messages have been logged today then the appender will still have a lock on yesterday's log file.

Nicko