title: Log4J2 each log file keeps grows in the same size defined in log4j2.xml
body: <p>My current application is on <code>Spring 3.2</code> / <code>Log4J2 2.3</code> / <code>Websphere 8.5</code> with JDK6, I have to stick to older version of Log4J2 because the application has to stay with JDK6.</p>
  
  <p>Now there is an interesting issue, seems caused by configuration or a bug in <code>Log4J2</code>, is that each time when I restart the application from server, then the RollingFile is working in a crazy mode, each new log file roll over grows in the size of the same size defined in <code>SizeBasedTriggeringPolicy</code>. Following is <code>Log4J2.xml</code> configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="DEBUG"&gt;
      &lt;Properties&gt;
          &lt;Property name="log-path"&gt;C:/Application/logs&lt;/Property&gt;
      &lt;/Properties&gt;
      &lt;Appenders&gt;
          &lt;Console name="STDOUT"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;%p -- %c -- %m%n&lt;/pattern&gt;
              &lt;/PatternLayout&gt;
          &lt;/Console&gt;
          &lt;RollingFile name="RollingFile" fileName="${log-path}/application-l4j-haha.log"
              filePattern="${log-path}/application-l4j-haha-%i.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;%p -- %c -- %m%n&lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size="2 MB" /&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="5" /&gt;
          &lt;/RollingFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Logger name="root" level="debug" additivity="false"&gt;
              &lt;AppenderRef  ref="RollingFile" level="debug" /&gt;
          &lt;/Logger&gt;
          &lt;Root level="debug" additivity="false"&gt;
              &lt;AppenderRef  ref="RollingFile" /&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>So the each file should maintain in <code>2Mb</code> and rotated in <code>5</code> files</p>
  
  <p>Here is the file output, it is apparent that the log file grows on each roll over and reach to a very big size, and each new file is bigger than previous one in exact <code>2Mb</code> !</p>
  
  <p><a href="https://i.stack.imgur.com/81Au8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/81Au8.png" alt="enter image description here"></a></p>
  
  <p>Also it is interestingly only happen when I <code>RESTART</code> the application. If I remove all the log files and let Log4J2 start from scratch then the log file roll over as expected, all files in the same size. However if I stop the application from server and start again then the log file goes all crazy again.</p>
  
  <p>Also this issue is found not only in Websphere but also Tomcat, so I guess it is not a server issue.</p>
  
  <p>Is there any known bug related to this issue and how to fix it?</p>