By Default we have the following values for following properties of a RollingFileAppender
- Rollingfileappender Log4net Config List
- Log4net Rollingfileappender App.config
- Log4net Rollingfileappender Config Example
- Rollingfileappender Log4net Configuration
- staticLogFileName = true
- countDirection = –1
- rollingStyle = Composite
- maxSizeRollBackups = 0 // be careful with this
- maximumFileSize = “10MB”
- datePattern = '.yyyy-MM-dd'
staticLogFileName indicates whether you need to keep writing (log) to the same file all the time. You will need to set it to false when using Date as the rolling style and you have large number of backups.
The RollingFileAppender extends the FileAppender and has the same behavior when opening the log file. The appender will first try to open the file for writing when ActivateOptions is called. This will typically be during configuration. I have downloaded the log4net.dll and added that as a service reference. One of the project I have created has app.config where I have made the following configurations. I have the following configuration, but I have not able to find any documentation on how to set a maximum backup files on date rolling style. I know that you can do this with size rolling style.
Optionally file.log.yyyy-mm-dd for current formated datePattern can by the currently logging file (or file.log.curSizeRollBackup (rollingStyle=Size) or even file.log.yyyy-mm-dd.curSizeRollBackup --- (rollingStyle=Composite)) This will make time based roll overs with a large number of backups much faster -- it won't have to rename all the backups!
Recommend to leave it at its default value “true”
Rollingfileappender Log4net Config List
countDirection when its value is –1, then newest logfile backup will always be file.log.1. hence this would involve more number of file renaming.
By default newer files have lower numbers. (countDirection < 0) ie. log.1 is most recent, log.5 is the 5th backup, etc.. countDirection > 0 does the opposite ie. log.1 is the first backup made, log.5 is the 5th backup made, etc. For infinite backups use countDirection > 0 to reduce rollOver costs.
rollingStyle can be either Date, Size or Composite. the default setting Composite, uses a combination of Size and Date settings. Thus if you have the datePattern set to “.yyyy-MM-dd” and maxSizeRollBackups set to 10, themn it will maintain 10 log backups for each day.
Log4net Rollingfileappender App.config
If you have the DatePattern set to “.yyyy-MM-dd HH:mm” and maxSizeRollbackups = 10 then it will maintain 10 logfile backups per minute
Log4net Rollingfileappender Config Example
Samples:
This will create infinite file backups with the countdirection > 0 so that the newest file has the latest/greatest name i.e. Mysql free download. log.5 for the newest backup (5th backup)
This is a Composite RollingFileAppender which keeps max of 10 1MB log backups every minute
Check out these tips about log4net
Posted on Tuesday, March 3, 2009 3:50 PM | Back to top