RollingFileAppender ClassApache log4net™ SDK Documentation
Appender that rolls log files based on size or date or both.
Inheritance Hierarchy

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

Namespace: log4net.Appender
Assembly: log4net (in log4net.dll) Version: 1.2.15.0 (1.2.15.0)
Syntax

public class RollingFileAppender : FileAppender
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 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   will reduce the number of file renamings to few or none.

Caution note 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 note Caution
A maximum number of backup files when rolling on date/time boundaries is not supported.
See Also