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: RollingFileAppender date pattern
Prev Next
You are not authorized to post a reply.

Author Messages
Hadley Willan

11/21/2008 3:04 AM  

Hi all,

 

I’m fine tuning the logging but it’s not quite right…

What I want is for the file to roll at midnight to a new date pattern file and roll within the same day if it reaches 50MB.

 

Eg. 

Start up application, 21-NOV-2008,   file gets created

myComp.Job Scheduler Service.20081121.log.txt

 

ideally, service continues to run, midnight rolls around and there’s a new file created for the 22nd and entries go to that.

myComp.Job Scheduler Service.20081122.log.txt

 

Problem is I’m not getting that… I’m getting a roll of the current file suffixed with the starting date? And logging continues to the same “21st” file pattern

myComp.Job Scheduler Service.20081121.log.txt ß latest entries in here

myComp.Job Scheduler Service.20081121.log.txt20081121 ß rolled file at midnight.

 

I’ve tried setting the rollingStyle to Date or Composite, but that hasn’t worked either.

 

This is possible??

Below is the config options. I’d appreciate any help.

 

Also, I may have misinterpreted the maxSizeRollBackups…  I’ve assumed that would keep 10 days worth of log files and then start deleting older log files for me, but I’m beginning to think that only applies to the rolls with a day?

So I’ll have to clean up any log files OLDER than 10 days?

 

Thanks in advance.

Hadley

 

 

  <!-- local messages-->

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

    <file type="log4net.Util.PatternString"

          value="${ALLUSERSPROFILE}\Application Data\Job Scheduler\%env{COMPUTERNAME}.Job Scheduler Service.%date{yyyyMMdd}.log.txt" />

    <!-- if an existing file is there, continue and append to it -->

    <appendToFile value="true" />

    <rollingStyle value="Composite" />

    <!-- roll on a full date change, use yyyyMMdd-HH for hourly -->

    <datePattern value="yyyyMMdd" />

    <!-- keeps up to 10 of these files, for an entire DAY, IGNORE The size  -->

    <maxSizeRollBackups value="10" />

    <!-- within a day, if the file size reaches 50MB, roll it too -->

    <!-- because it's text, Log file service will zip this down to around 5MB  -->

    <!-- 5MB for mailing a log file is a safe size, most servers won't bounce that -->

    <maximumFileSize value="50MB" />

    <!-- layout, including our custom property, customAssemblyName-->

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

      <conversionPattern value="%-5level %date %-50%type %-40%method %message%newline" />

    </layout>

  </appender>


************************************************************************
Bunnings Legal Disclaimer:

1) This email is confidential and may contain legally privileged
information. If you are not the intended recipient, you must not
disclose or use the information contained in it. If you have received
this email in error, please notify us immediately by return email and
delete the document.

2) All emails sent to and sent from Bunnings Group Limited.
are scanned for content. Any material deemed to contain inappropriate
subject matter will be reported to the email administrator of all
parties concerned.
************************************************************************
Hadley Willan

11/24/2008 7:26 AM  

Okay,

 

I wrote a small test app so I could get this right.  Seems to have helped as I think I understand this better now.

  1. Yes it is possible to have the appender roll the filename on the date change
  2. Yes it is possible to specify where the appender places the date pattern

 

If I use

    <staticLogFileName value="false" />

Then the file name is always generated on the date roll over.

 

If I use a better date format string with a literal tacked on the end, I get the file names I’m after.

    <datePattern value="yyyyMMdd’.log.txt’" />

 

All you need to do is modify the original file value to exclude the original %date I was using, as the appender adds this for me.

    <file type="log4net.Util.PatternString"

          value="${ALLUSERSPROFILE}\Application Data\Job Scheduler\%env{COMPUTERNAME}.Job Scheduler Service" />

 

Then I get the filename pattern I’m after.

myComp.Job Scheduler Service.20081121.log.txt

myComp.Job Scheduler Service.20081122.log.txt

myComp.Job Scheduler Service.20081123.log.txt

 

The only question that remains is…

Can I specify a pattern for WHERE the appender should place the suffix of what number this is when doing a maxSizeRollBackups ??

<maxSizeRollBackups value="10" />

 

I’ll keep 10 files for a given day. But the file name is coming out as…

myComp.Job Scheduler Service.20081121.log.txt

myComp.Job Scheduler Service.20081121.log.txt.1

myComp.Job Scheduler Service.20081121.log.txt.2

myComp.Job Scheduler Service.20081121.log.txt.3

 

whereas I’d prefer

myComp.Job Scheduler Service.20081121.log.txt

myComp.Job Scheduler Service.20081121.1.log.txt

myComp.Job Scheduler Service.20081121.2.log.txt

myComp.Job Scheduler Service.20081121.3.log.txt

 

Thanks in advance if someone can help with this.

Hadley

 

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > RollingFileAppender date pattern



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