title: Logging time incorrect in my custom Log4j2 XML configuration file Java
body: <p>I am new to log4j2. Previously I am using log4j. The reason I am migrating into part 2 is for Asynchronous logging. After searching Internet I am able to write a configuration file that actually creates two log files "Errors.log" and "Messages.log". Now the problem is : I would be communicating with Servers that are kept far away from me. I wrote a client that communicates with the server and sends a request and in back the Server sends me a response. In any situation it takes at least 10 milli-seconds for the request to reach the Server and get back the response from it. But in my log files it is showing that the request sent to the Server and receive from the Server is at same time (Same milli-second). I am using the Asynchronous logging. Is this causing the wrong timestamp? or else the policies which I have used are creating these issues?</p>
  
  <p>Below is my Log4j2 XML CONFIG file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;Configuration status="warn"&gt;
    &lt;Appenders&gt;
    &lt;File name="my_file_appender" fileName="LOG4j_LOGS/Errors.log" immediateFlush="false" append="false"&gt;
        &lt;PatternLayout&gt;
         &lt;Pattern&gt;%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n&lt;/Pattern&gt;
        &lt;/PatternLayout&gt;
      &lt;/File&gt;
      &lt;Async name="async_appender"&gt;
      &lt;AppenderRef ref="my_file_appender" /&gt;
     &lt;/Async&gt;
       &lt;!-- file appender --&gt;
       &lt;RollingFile name="Error-log" fileName="LOG4j_LOGS/Messages.log"
                   filePattern="LOG4j_LOGS/Messages-%d{yyyy-MM-dd}.log"&gt;
        &lt;!-- log pattern --&gt;   
           &lt;PatternLayout&gt;
              &lt;Pattern&gt;%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n&lt;/Pattern&gt;
          &lt;/PatternLayout&gt;
          &lt;!-- set file size policy --&gt;
          &lt;Policies&gt;
             &lt;TimeBasedTriggeringPolicy /&gt;
              &lt;SizeBasedTriggeringPolicy size="100 MB" /&gt;
          &lt;/Policies&gt;
          &lt;DefaultRolloverStrategy max="25"/&gt;
      &lt;/RollingFile&gt;   
    &lt;/Appenders&gt;   
    &lt;Loggers&gt;
        &lt;Logger name="Error-log" level="info" additivity="false"&gt;
         &lt;appender-ref ref="Error-log" level="debug"/&gt;
         &lt;/Logger&gt;
         &lt;Root level="info" includeLocation="false"&gt;
              &lt;AppenderRef ref="async_appender"/&gt;
        &lt;/Root&gt;
    &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>Can anyone please check my CONFIG file. All I want is to create two separate log files, one for storing info messages and other for storing errors. And this should create a new file every time I run my application and it should not delete the previous logs. The size of the logs can be anything. If the size has exceeded it should create a new file and write the data into it. No matter how many days I run the application the daily logs needs to be stored and the entire process has to be done in Asynchronously.</p>
  
  <p>I am also using the below VM options for logging asynchronously :</p>
  
  <pre><code> -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
  </code></pre>