Discussion:
Compress & Delete old logs
Michael Schall
2006-05-30 16:07:28 UTC
Permalink
Is there a way with the rollingfile appender to have it compress
itself as it is rolling to the next file? I would name my logs by
date, and would like the old files to compress (zip, cab, some format
readable without extra installs) as a new file is being created.

Also, is it possible to have a max number of files saved? We would
like to only keep the last x days of logs.

So day to day the files would be compressed and after x days, the
compressed files would be removed.

Is this possible currently, or planned in the future?

Mike
Ron Grabowski
2006-05-30 20:49:21 UTC
Permalink
The RollingFileAppender does not have compression support built-in.
What should happen if I set my rolling log file size to 200mb? Should
my application stop responding until the compression process is
complete?

According to this page:

http://tinyurl.com/q48hv
http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.MaxSizeRollBackups.html

The MaxSizeRollBackups property is "the maximum number of backup files
that are kept before the oldest is erased".

Are you able to roll files on a daily basis then run another program
every day to compress old log files? There may be general purpose
command line utilities that do this already.
Post by Michael Schall
Is there a way with the rollingfile appender to have it compress
itself as it is rolling to the next file? I would name my logs by
date, and would like the old files to compress (zip, cab, some format
readable without extra installs) as a new file is being created.
Also, is it possible to have a max number of files saved? We would
like to only keep the last x days of logs.
So day to day the files would be compressed and after x days, the
compressed files would be removed.
Is this possible currently, or planned in the future?
Mike
Michael Schall
2006-05-30 21:08:32 UTC
Permalink
Thanks for the reply...

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\Projects\IaDoc\Icon\log\web.log" />
<appendToFile value="true" />
<maximumFileSize value="100MB" />
<maxSizeRollBackups value="-1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%5level [%date] [%thread]
%-30.30logger{2} %message%newline" />
</layout>
</appender>

In my case at least I would like it to write a 100mb file, create a
new one to log to, and then compress the original file in a separate
thread to that dates zip file. For example lets say that my
application logs 500mb a day. When reaching the 100mb limit it would
rename the file to web.log.<date> as it does today and create a new
web.log. It would then create a new thread that would move that log
file to a zip archive web.log.<date>.zip. When the limit is reached
again, the same thing would happen only web.log.<date>-x file that is
created would be moved into the existing web.log.<date>.zip file.

Also the MaxSizeRollBackups is per time based group. ("The maximum
applies to each time based group of files and not the total.") We
don't set a time, so it defaults to 1 day. We have that setting set
to -1 so that we don't delete any for that day. I would like a
setting that does it per appender so I can keep only the last 14 days
worth of files. This request is so we don't need to have an external
process to clean the logs. It is our policy that the one that does
the logging, cleans up the logging.

Thoughts?
Post by Ron Grabowski
The RollingFileAppender does not have compression support built-in.
What should happen if I set my rolling log file size to 200mb? Should
my application stop responding until the compression process is
complete?
http://tinyurl.com/q48hv
http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.MaxSizeRollBackups.html
The MaxSizeRollBackups property is "the maximum number of backup files
that are kept before the oldest is erased".
Are you able to roll files on a daily basis then run another program
every day to compress old log files? There may be general purpose
command line utilities that do this already.
Post by Michael Schall
Is there a way with the rollingfile appender to have it compress
itself as it is rolling to the next file? I would name my logs by
date, and would like the old files to compress (zip, cab, some format
readable without extra installs) as a new file is being created.
Also, is it possible to have a max number of files saved? We would
like to only keep the last x days of logs.
So day to day the files would be compressed and after x days, the
compressed files would be removed.
Is this possible currently, or planned in the future?
Mike
Phillip Ring
2006-05-30 21:11:47 UTC
Permalink
If you are using the .Net Framework v2.x, you can add the compression
functionality yourself by using the System.IO.Compression.GZipStream to
compress the file.

Phillip Ring
-----Original Message-----
Sent: Tuesday, May 30, 2006 3:49 PM
To: Log4NET User
Subject: Re: Compress & Delete old logs
The RollingFileAppender does not have compression support built-in.
What should happen if I set my rolling log file size to 200mb? Should
my application stop responding until the compression process is
complete?
http://tinyurl.com/q48hv
http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFile
Appender.MaxSizeRollBackups.html
The MaxSizeRollBackups property is "the maximum number of backup files
that are kept before the oldest is erased".
Are you able to roll files on a daily basis then run another program
every day to compress old log files? There may be general purpose
command line utilities that do this already.
Post by Michael Schall
Is there a way with the rollingfile appender to have it compress
itself as it is rolling to the next file? I would name my logs by
date, and would like the old files to compress (zip, cab, some format
readable without extra installs) as a new file is being created.
Also, is it possible to have a max number of files saved? We would
like to only keep the last x days of logs.
So day to day the files would be compressed and after x days, the
compressed files would be removed.
Is this possible currently, or planned in the future?
Mike
Continue reading on narkive:
Loading...