title: How to save logs into file with timestamp with log4j2
body: <p>i have a little problem. I had to change my logging implementation from org.apache.commons.logging to org.apache.logging.log4j. I saved my logs into a "log" directory and each file got a appended timestamp. 
  I used the following .xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  
  &lt;include resource="org/springframework/boot/logging/logback/base.xml"/&gt;
  
     &lt;logger name="org.springframework.web" level="INFO"/&gt;
  
     &lt;timestamp key="myTimestamp" timeReference="contextBirth" datePattern="yyyy-MM-dd'_'HH-mm-ss"/&gt;
  
      &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt;
  
          &lt;encoder&gt;
              &lt;pattern&gt;%d{HH:mm:ss.SSS}  - %msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  
      &lt;appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;file&gt;/logs/app-${myTimestamp}.log&lt;/file&gt;
          &lt;encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"&gt;
              &lt;Pattern&gt;%d{yyyy-MM-dd_HH:mm:ss} - %msg%n&lt;/Pattern&gt;
          &lt;/encoder&gt;
  
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"&gt;
              &lt;FileNamePattern&gt;app.%i{yyyy-MM-dd_HH:mm:ss.SSS}}.log&lt;/FileNamePattern&gt;
          &lt;/rollingPolicy&gt;
  
          &lt;triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"&gt;
              &lt;MaxFileSize&gt;30MB&lt;/MaxFileSize&gt;
          &lt;/triggeringPolicy&gt;
      &lt;/appender&gt;
  
      &lt;logger name="com....." level="INFO" additivity="false"&gt;
          &lt;appender-ref ref="STDOUT" /&gt;
          &lt;appender-ref ref="FILE" /&gt;
      &lt;/logger&gt;
  
      &lt;root level="INFO"&gt;
          &lt;appender-ref ref="STDOUT" /&gt;
      &lt;/root&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Now i wanted to extend my xml file with log4j2, because of some new environments. But i also want to save it in the "logs" directory again. I tried different methods via the documentation and <a href="http://www.baeldung.com" rel="nofollow noreferrer">http://www.baeldung.com</a>, but i don't get. My application always writes in the my app.log again without timestamp. How can i realize it? Where is the mistake in my new .xml ? 
  I thought with this</p>
  
  <pre><code>filePattern="logs/ldapmicroservice.%d{MM-dd-yyyy-HH-mm}.log.gz"
  </code></pre>
  
  <p>i define the new pattern of my file?
  This is my new .xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="WARN" monitorInterval="30"
  
      packages="com......"&gt;
      &lt;Properties&gt;
          &lt;Property name="LOG_PATTERN"&gt;
              %d{yyyy-MM-dd HH:mm:ss.SSS} %5p %X{mdcData} --- %-40.40c{1.} : %m%n%ex
          &lt;/Property&gt;
      &lt;/Properties&gt;
  
      &lt;Appenders&gt; 
          &lt;RollingFile 
              name="FILE" fileName="/logs/app.log" 
              filePattern="logs/app.%d{MM-dd-yyyy-HH-mm}.log.gz"
              ignoreExceptions="false"&gt;
                  &lt;PatternLayout&gt;
                      &lt;Pattern&gt;%d{yyyy-MM-dd HH:mm:ss} %p %m%n&lt;/Pattern&gt;
                  &lt;/PatternLayout&gt;
                  &lt;TimeBasedTriggeringPolicy /&gt;
          &lt;/RollingFile&gt; 
  
          &lt;Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true"&gt;
              &lt;PatternLayout pattern="${LOG_PATTERN}" /&gt;
          &lt;/Console&gt;  
          &lt;CloudantAppender name="CloudantAppender" 
              database="logs"
              ......
              &lt;PatternLayout pattern="${LOG_PATTERN}"/&gt;
          &lt;/CloudantAppender&gt;
      &lt;/Appenders&gt;
  
      &lt;Loggers&gt;
          &lt;Logger name="com...." level="debug" additivity="false"&gt;
              &lt;AppenderRef ref="FILE" /&gt;
              &lt;AppenderRef ref="ConsoleAppender" /&gt;
              &lt;AppenderRef ref="CloudantAppender" /&gt;
          &lt;/Logger&gt;
  
          &lt;Root level="info"&gt;
              &lt;AppenderRef ref="FILE" /&gt;
              &lt;AppenderRef ref="ConsoleAppender" /&gt;
              &lt;AppenderRef ref="CloudantAppender" /&gt;  
          &lt;/Root&gt;
  
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>