logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Rolling File Appender provided by Log4Net
Date Wed, 17 Aug 2005 12:14:10 GMT
You should create your custom appender in a separate assembly. Your
assembly can then reference ICSharpCode.SharpZipLib. 

If you intend to subclass the RollingFileAppender and you need to make
changes to the code to allow that you should copy the current
RollingFileAppender (preferably the latest version in CVS) into your own
assembly. Try to make the minimal set of changes to the
RollingFileAppender code necessary to allow your subclass to work, e.g.
marking methods as virtual. Build your subclass with your additional
logic etc.. Note that a file may be rolled (by calling RollFile) more
than once, so you will need to check if you have already compressed the
file. If you change the names of files made by RollFile then you will
need to modify the RollingFileAppender to understand that when looking
for files.

To test your subclass use various different settings
RollingStyle=Once/Size/Date/Composite and StaticLogFileName=true/false.
It is also important to test starting the appender when there are
existing archived files!


> -----Original Message-----
> From: Shaily Goel [mailto:gshaily@novell.com] 
> Sent: 17 August 2005 06:48
> To: log4net-user@logging.apache.org; Nicko Cadell
> Subject: RE: Rolling File Appender provided by Log4Net
> hi
> In order to compress the archive files created by 
> Log4Net.RollingFileAppender I did following things:
> 1.  I created a CustomAppender by extending Rolling File 
> Appender  and tried overwriting "protected void 
> RollFile(string fromFile, string toFile) " function which 
> rolls the file. But I am unable to overwrite this method as 
> they are not declared as "virtual" in 
> log4net.RollingFileAppender. So I am left with the option of 
> coping the RollingFileAppender code and then modifying the 
> RollFile method in it so as to make it work as per my 
> requirements. But this is not a good practice. Hence, I 
> request you to make the methods in 
> log4net.RollingFileAppender as "Virtual" so that other people 
> can overwrite these methods as per their requirement.
> 2. The second option can be I implement the Zipping 
> Functionality in RollingFileAppender and submit the code back 
> to community. For zipping I am using 
> "ICSharpCode.SharpZipLib" , a free C# compression library . I 
> am thinking of adding a new property called as "ZipFile" in 
> RollingFileAppender which can be set to true/False. If 
> "true", then RollFile method will roll and zip the file. But 
> all this will make log4net dependent on ""ICSharpCode.SharpZipLib". 
> Please let me know what should I do?
> Note: My requirements does not allow me to create a second 
> process or script that run every day to compress log files.
> Thanks
> Shaily
> >>> nicko@neoworks.com 06/21/05 10:14 PM >>>
> If you need to create a custom appender that compresses the 
> archive files you will need to create a new assembly with a 
> copy of the RollingFileAppender code in it. The RollXXX 
> methods are used to roll the old log file out of the way. 
> These all call into the RollFile method, so you may be able 
> to extend the appender at that point. The appender currently 
> just uses System.IO.File.Move to roll the file.
> You can find compression libraries for .net which will allow 
> you to zip the old files. As zipping up the file may be a 
> slow operation I suggest that you move the file to a 
> temporary name and then compress it on a separate thread.
> Cheers,
> Nicko 
> > -----Original Message-----
> > From: Shaily Goel [mailto:gshaily@novell.com]
> > Sent: 21 June 2005 06:07
> > To: log4net-user@logging.apache.org
> > Subject: Rolling File Appender provided by Log4Net
> > 
> > We are planning to use Rolling File Appender provided by Log4net.
> > 
> > Our requirements are like below:
> > 
> > 1. Rolling File Appender should be able to log the messages into a 
> > local file with an extension of .log 2. It should write the 
> message in 
> > xml format in local file.
> > 3. It should be able to roll log files based on either size 
> or date. 
> > When the current log file reaches a particular size/date, a new log 
> > file is rolled into its place.
> > 4. The old log file should be stored in a compressed format 
> until the 
> > maximum number of log files is reached, causing the oldest 
> log file to 
> > be deleted.
> > 
> > 
> > I found that all my above requirements are met by Rolling File 
> > Appender provided by log4net except that "The old log file 
> should be 
> > stored in a compressed format ".
> > 
> > I want to know whether Rolling File appender internally 
> store all old 
> > log files in compressed format??If not, how can we achieve this ?
> > 
> > 
> > Thanks
> > Shaily
> > 
> > 
> > 
> >  
> > 

View raw message