log4net SDK Reference

RollingFileAppender Class

Appender that rolls log files based on size or date or both.

For a list of all members of this type, see RollingFileAppender Members.

System.Object
   log4net.Appender.AppenderSkeleton
      log4net.Appender.TextWriterAppender
         log4net.Appender.FileAppender
            log4net.Appender.RollingFileAppender

[Visual Basic]
Public Class RollingFileAppender
    Inherits FileAppender
[C#]
public class RollingFileAppender : FileAppender

Thread Safety

This type is not safe for multithreaded operations.

Remarks

RollingFileAppender can roll log files based on size or date or both depending on the setting of the RollingStyle property. When set to Size the log file will be rolled once its size exceeds the MaximumFileSize. When set to Date the log file will be rolled once the date boundary specified in the DatePattern property is crossed. When set to Composite the log file will be rolled once the date boundary specified in the DatePattern property is crossed, but within a date boundary the file will also be rolled once its size exceeds the MaximumFileSize. When set to Once the log file will be rolled when the appender is configured. This effectively means that the log file can be rolled once per program execution.

A of few additional optional features have been added:

Note   

For large or infinite numbers of backup files a CountDirection greater than zero is highly recommended, otherwise all the backup files need to be renamed each time a new backup is created.

When Date/Time based rolling is used setting StaticLogFileName to true will reduce the number of file renamings to few or none.

CAUTION   

Changing StaticLogFileName or CountDirection without clearing the log file directory of backup files will cause unexpected and unwanted side effects.

If Date/Time based rolling is enabled this appender will attempt to roll existing files in the directory without a Date/Time tag based on the last write date of the base log file. The appender only rolls the log file when a message is logged. If Date/Time based rolling is enabled then the appender will not roll the log file at the Date/Time boundary but at the point when the next message is logged after the boundary has been crossed.

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. If the file cannot be opened for writing the appender will attempt to open the file again each time a message is logged to the appender. If the file cannot be opened for writing when a message is logged then the message will be discarded by this appender.

When rolling a backup file necessitates deleting an older backup file the file to be deleted is moved to a temporary name before being deleted.

CAUTION   

A maximum number of backup files when rolling on date/time boundaries is not supported.

Requirements

Namespace: log4net.Appender

Assembly: log4net (in log4net.dll)

See Also

RollingFileAppender Members | log4net.Appender Namespace