title: How does Log4j2 DefaultRolloverStrategy's max attribute really work?
body: <p>I've configured a <code>RollingRandomAccessFileAppender</code> with only the <code>OnStartupTriggeringPolicy</code> set, but when I set the max attribute of the <code>DefaultRolloverStrategy</code> to some number, the logs keep generating past that amount indefinitely.</p>
  
  <p>Here's my <strong>log4j2.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="WARN"&gt;
      &lt;Appenders&gt;
          &lt;Console name="Console" target="SYSTEM_OUT"&gt;
              &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/&gt;
          &lt;/Console&gt;
          &lt;RollingRandomAccessFile 
              name="RollingRAF" 
              fileName="logs/app.log"
              filePattern="logs/app-%d{dd-MMM-yyyy@HH.mm.ss}.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;Pattern&gt;%d %p %c{1.} %m%n&lt;/Pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;OnStartupTriggeringPolicy /&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="5"/&gt;
          &lt;/RollingRandomAccessFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Logger name="myLogger" level="warn"&gt;
              &lt;AppenderRef ref="RollingRAF"/&gt;
          &lt;/Logger&gt;
          &lt;Root level="error"&gt;
              &lt;AppenderRef ref="Console"/&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>Is it because I don't have an iterator in my name pattern?</p>
  
  <p>Is it because my file name precision is set to seconds?</p>
  
  <p>Is it because I only have the <code>OnStartupTriggeringPolicy</code> set?</p>
  
  <p>Or what's going on here?</p>
  
  <p>My goal here was to set up a rolling configuration that will log the last 5 application runs.</p>