////
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
////

[#rollingfileappender]
= RollingFileAppender

The `RollingFileAppender` extends the functionality of the `FileAppender` by adding the ability to automatically roll over log files based on specified criteria, such as file size or time intervals.

This appender is useful for managing log files in production environments where log data grows over time and older logs should be preserved while maintaining a manageable file size.

The following example shows how to configure the `RollingFileAppender` to write to the file `MyApp.log`.

The file written to will always be named `MyApp.log` because the `StaticLogFileName` parameter is specified.

The file will be rolled based on a size constraint (`RollingStyle`), and old log files will be archived when the size limit is reached.
Up to 10 (`MaxSizeRollBackups`) old files of 100 KB each (`MaximumFileSize`) will be kept.

These rolled files will be named: `MyApp.log.1`, `MyApp.log.2`, `MyApp.log.3`, etc.

This allows you to keep a set number of backup log files, which can be helpful for both auditing and troubleshooting, while ensuring that log file growth doesn't fill up disk space.

[source,xml]
----
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="MyApp.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="100KB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>
----

This example show how to configure the `RollingFileAppender` to roll log files on a date period.

This example will roll the log file every minute.
To change the rolling period adjust the `DatePattern` value.
For example, a date pattern of "yyyyMMdd" will roll every day.

See `System.Globalization.DateTimeFormatInfo` for a list of available patterns.

[source,xml]
----
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="MyApp.log" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <datePattern value="yyyyMMdd-HHmm" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>
----

This example show how to configure the `RollingFileAppender` to roll log files on a date period and within a date period on file size.

For each day only the last 10 files of 1MB will be kept.

[source,xml]
----
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="MyApp.log" />
  <appendToFile value="true" />
  <rollingStyle value="Composite" />
  <datePattern value="yyyyMMdd" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="1MB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>
----

This example show how to configure the `RollingFileAppender` to roll log files once per program execution.

The `appendToFile` property is set to false to prevent the appender from overwriting the existing files.

The `maxSizeRollBackups` is set to negative 1 to allow an infinite number of backup files.

The file size does have to be limited but here it is set to 50 Gigabytes which, if a log file exceeds this size limit during a single run then it will also be rolled.

[source,xml]
----
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="MyApp.log" />
  <appendToFile value="false" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="-1" />
  <maximumFileSize value="50GB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>
----