title: log4j2 - limiting the number of log files
body: <p>I have the following log4j2.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration status="OFF"&gt;
    &lt;appenders&gt;
      &lt;RollingFile name="testLog" fileName="test.log" filePattern="" append="false"&gt;
        &lt;PatternLayout pattern="[%t] %-5level - %msg%n%n"/&gt;
      &lt;SizeBasedTriggeringPolicy size="5mb" /&gt;
      &lt;/RollingFile&gt;
    &lt;/appenders&gt;
    &lt;loggers&gt;
      &lt;logger name="TestsLogger" level="trace" additivity="false"&gt;
        &lt;appender-ref ref="testLog"/&gt;
      &lt;/logger&gt;
      &lt;root level="debug"&gt;
        &lt;appender-ref ref="testLog"/&gt;
      &lt;/root&gt;
    &lt;/loggers&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>How can I modify this configuration such that</p>
  
  <ol>
  <li>Instead of overwriting the same logfile over and over again a new file is created after the 5mb limit has been reached. It would be nice to have something like test1.log, test2.log and so on.</li>
  <li><p>How can I limit the number of partial log files created in 1.? What I want to achieve is a scheme like the following:</p>
  
  <pre><code>creating test1.log [present log files: test1.log]
  test1.log - 5mb limit reached
  creating test2.log [present log files: test1.log, test2.log]
  test2.log - 5mb limit reached
  creating test3.log [present log files: test2.log, test3.log]
  test3.log - 5mb limit reached
  creating test4.log [present log files: test3.log, test4.log]
  and so on
  </code></pre></li>
  </ol>
  
  <p>Does anyone know, how to achieve something like that? Of course it would be nice, if something like that was possible with log4j2 alone. But maybe there is a way to combine log4j2 with some kind of external program that would run alongside the main Java application and delete superfluous log files, while keeping the two last log files intact. So if anyone has at least a suggestion for 1., it may be already, what I'm looking for. Because I may be able to write a program for the 2nd part. Of course it would be awesome, if the 2nd part could be done with log4j2 as well.</p>