Monday, May 21, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Deleting old logs
Prev Next
You are not authorized to post a reply.

Author Messages
M.Suarez

06/15/2009 11:21 PM  


Hi,

I am trying to just have the latest 2 log files of my application, thus I
have configured the log4net as follows:

<log4net>
    <appender name="RollingFile"
type="log4net.Appender.RollingFileAppender">
      <file value="d:\netapps\logfiles\MyApp.log" />
      <appendToFile value="true" />
        <MaximumFileSize value="100KB"/>
        <MaxSizeRollBackups value="2" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger -
%message%newline" />
      </layout>
    </appender>

    <!-- Set root logger level to INFO and its only appender to Console and
RollingFile-->
    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFile" />
    </root>
  </log4net>

However, there will be more than then two expected log files, this is
because:
"The maximum applies to each time based group of files and not the total"
(http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.MaxSizeRollBackups.html)

How should I configure log4net then to only store the latest two files? Any
help will be greatly appreciate it.

Regards,
Monica

Ron Grabowski

06/17/2009 12:05 AM  


What happens when you add <RollingMode value="Size" />?

http://logging.apache.org/log4net/release/config-examples.html


Radovan Raszka

06/17/2009 7:37 AM  

Deleting old log files is thing I'm interested in too.
According to doc I think MaxSizeRollBackups has reason only when logs are rolled over size (you have more log files per day).
But it probably doesn't work when log is rolled over date only (one log per day only). Is it true or not?
My appender is configured as follows:
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <appendToFile value="true" />
      <file value="Log/Service.log" />
      <layout type="log4net.Layout.PatternLayout">
         <conversionPattern value="%date{HH:mm:ss,fff} %5level [%2thread] %message (%logger{1}:%line)%n" />
      </layout>
      <rollingStyle value="Date" />
      <Threshold value="DEBUG" />
</appender>
But I don't know how to set it to keep last 10 logs. Now I delete old logs in my app - I run clean procedure once a day and delete logs whose last modification was done before 10 days...
Radovan

M.Suarez

06/18/2009 10:44 PM  


Thanks for tip. I will add that and see what happens. Will let you know.

One thing, you have put there the link to the log4net config examples,
however none of them seem to be using the property you just mention.

Also I found this: https://issues.apache.org/jira/browse/LOG4NET-208

M.Suarez

06/18/2009 10:53 PM  


I have just checked and this is what happened:
log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [RollingMode]
to se
t object on [log4net.Appender.RollingFileAppender]

M.Suarez

06/18/2009 10:55 PM  


I too clear the old log files from my app, but i believe that there must be a
way to configure this, thus the log4net takes care of it, right? or doesn't?


Ron Grabowski

06/19/2009 6:05 AM  


Hopefully you glanced at the public properties on RollingFileAppender and realized that the property is actually called RollingStyle:

 <RollingStyle value="Size" />


Ron Grabowski

06/19/2009 6:15 AM  


While this might not be the exact answer you were looking for, don't forget that sometimes its easier to just write the 3 lines of code yourself for deleting old log files and move on to other things:

foreach (string file in Directory.GetFiles("c:\\logs", "*.log"))
{
    if (DateTime.Today.Subtract(File.GetLastWriteTime(file)).Days > 10)
    {
        File.Delete(file);
    }
}

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Deleting old logs



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement