You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by moonstone <ac...@yahoo.com> on 2014/02/17 20:58:03 UTC

how to keep 3 days of logs

I need to keep 3 days of logging information from my application, which runs
once per day.  For example, if I start with 3 days worth of logging
information retained:
CustomerDataTransfer.2014-02-15.txt
CustomerDataTransfer.2014-02-14.txt
CustomerDataTransfer.2014-02-13.txt

When I run the application on Feb 17, I'd like to have these 3 files
retained
CustomerDataTransfer.2014-02-17.txt
CustomerDataTransfer.2014-02-15.txt
CustomerDataTransfer.2014-02-14.txt

Is it possible to configure log4net this way?

Here's the configuration information I currently use.

    <appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
      
      
      <datePattern value="'.'yyyy-MM-dd'.txt'" />
      
      
      
      
      
      <layout type="log4net.Layout.PatternLayout">
        
        
        
      </layout>
    </appender>



--
View this message in context: http://apache-logging.6191.n7.nabble.com/how-to-keep-3-days-of-logs-tp44594.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

AW: AW: how to keep 3 days of logs

Posted by Dominik Psenner <dp...@gmail.com>.
I think that what he is searching for is the combination of MaxBackupIndex=3
and rolling style "Once". Rolling by date won't work with the backup index
detection mechanisms.

 

Von: George Mauer [mailto:gmauer@gmail.com] 
Gesendet: Dienstag, 18. Februar 2014 16:19
An: Log4NET User
Betreff: Re: AW: how to keep 3 days of logs

 

I believe that is the point of the maxBackupIndex setting
<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileApp
ender.html#setMaxBackupIndex(int)>  on RollingFileAppender. I'm not 100%
sure what the xml for it is as I always roll based on file size but it
shouldn't be too hard to google or guess.

 

On Tue, Feb 18, 2014 at 8:56 AM, moonstone <acedog032000@yahoo.com
<ma...@yahoo.com> > wrote:

Thanks for your reply.  I was not clear in stating my goal.  The application
runs once per day.  With the log4net configuration that I have currently, I
get 1 log file each day with the date in the file name.  The number of log
files increases by one each day.  A user has to delete old log files by
sorting on the file date and deleting the oldest ones.  The customer only
wants to keep the log files from the last 3 runs of the application.  I can
write the code to delete the old files, but I thought I should check if
log4net can do it.

My configuration is shown below:

<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">


        <datePattern value="'.'yyyy-MM-dd'.txt'" />





        <layout type="log4net.Layout.PatternLayout">



        </layout>
</appender>




--

View this message in context:
http://apache-logging.6191.n7.nabble.com/how-to-keep-3-days-of-logs-tp44594p
44630.html

Sent from the Log4net - Users mailing list archive at Nabble.com.

 


Re: AW: how to keep 3 days of logs

Posted by George Mauer <gm...@gmail.com>.
I believe that is the point of the maxBackupIndex
setting<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html#setMaxBackupIndex(int)>
on
RollingFileAppender. I'm not 100% sure what the xml for it is as I always
roll based on file size but it shouldn't be too hard to google or guess.


On Tue, Feb 18, 2014 at 8:56 AM, moonstone <ac...@yahoo.com> wrote:

> Thanks for your reply.  I was not clear in stating my goal.  The
> application
> runs once per day.  With the log4net configuration that I have currently, I
> get 1 log file each day with the date in the file name.  The number of log
> files increases by one each day.  A user has to delete old log files by
> sorting on the file date and deleting the oldest ones.  The customer only
> wants to keep the log files from the last 3 runs of the application.  I can
> write the code to delete the old files, but I thought I should check if
> log4net can do it.
>
> My configuration is shown below:
> <appender name="RollingLogFileAppender"
> type="log4net.Appender.RollingFileAppender">
>
>
>         <datePattern value="'.'yyyy-MM-dd'.txt'" />
>
>
>
>
>
>         <layout type="log4net.Layout.PatternLayout">
>
>
>
>         </layout>
> </appender>
>
>
>
>
> --
> View this message in context:
> http://apache-logging.6191.n7.nabble.com/how-to-keep-3-days-of-logs-tp44594p44630.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>

Re: AW: how to keep 3 days of logs

Posted by moonstone <ac...@yahoo.com>.
Thanks for your reply.  I was not clear in stating my goal.  The application
runs once per day.  With the log4net configuration that I have currently, I
get 1 log file each day with the date in the file name.  The number of log
files increases by one each day.  A user has to delete old log files by
sorting on the file date and deleting the oldest ones.  The customer only
wants to keep the log files from the last 3 runs of the application.  I can
write the code to delete the old files, but I thought I should check if
log4net can do it.

My configuration is shown below:
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
	
	
	<datePattern value="'.'yyyy-MM-dd'.txt'" />
	
	
	
	
	
	<layout type="log4net.Layout.PatternLayout">
		
		
		
	</layout>
</appender>




--
View this message in context: http://apache-logging.6191.n7.nabble.com/how-to-keep-3-days-of-logs-tp44594p44630.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

AW: how to keep 3 days of logs

Posted by Dominik Psenner <dp...@gmail.com>.
Hey

Since that your application starts every few days there would have to be a
persistent storage of meta information to share the information "rotate in X
days" or a logic "roll if day modulo 3 is 0", but unfortunately log4net does
not implement either feature. The rolling file appender implements the
rolling modes Once, Size, Date and Composite:

http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAp
pender.RollingMode.html

That means you will have to work around that by either:
* implement your own appender
* extend an existing one with the feature you need
* set up a task that behaves like linux' logrotate
* append your events into a database where you can group the events in
3-days chunks when selecting them out of the database

Best regards
Dominik