title: how to fix Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile?
body: <p>I am using spring boot(2.2.0.RELEASE) configure with log4j2. While deploy war in tomcat getting some run time exception.I have set system property(logging name) then that name mentioned in log4j properties.</p>
  <p><strong>Runtime Error :</strong></p>
  <pre><code>ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
  </code></pre>
  <p><code>Log4j.xml</code>:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Configuration status=&quot;INFO&quot;&gt;
      &lt;Properties&gt;
          &lt;Property name=&quot;LOG_PATTERN&quot;&gt;%d{yyyy-MM-dd'@'HH:mm:ss}|[%t]|[AM]|%p|%X{Slf4jMDCFilter.UUID}|%c{1}()
              %M(%L) %m%n        &lt;/Property&gt;
          &lt;Property name=&quot;APP_LOG_ROOT&quot;
                    value=&quot;logs/${sys:finlog}&quot;&gt;
          &lt;/Property&gt;
      &lt;/Properties&gt;
      &lt;Appenders&gt;
          &lt;RollingFile name=&quot;errorlog&quot;
                       fileName=&quot;${APP_LOG_ROOT}/error.log&quot;
                       filePattern=&quot;${APP_LOG_ROOT}/ErrorLog-%d{yyyy-MM-dd}-%i.log&quot;&gt;
              &lt;LevelRangeFilter minLevel=&quot;ERROR&quot; maxLevel=&quot;ERROR&quot;
                                onMatch=&quot;ACCEPT&quot; onMismatch=&quot;DENY&quot;/&gt;
              &lt;PatternLayout pattern=&quot;${LOG_PATTERN}&quot;/&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size=&quot;19500KB&quot;/&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
          &lt;RollingFile name=&quot;debugLog&quot;
                       fileName=&quot;${APP_LOG_ROOT}/debug.log&quot;
                       filePattern=&quot;${APP_LOG_ROOT}/DebugLog-%d{yyyy-MM-dd}-%i.log&quot;&gt;
              &lt;LevelRangeFilter minLevel=&quot;DEBUG&quot; maxLevel=&quot;DEBUG&quot;
                                onMatch=&quot;ACCEPT&quot; onMismatch=&quot;DENY&quot;/&gt;
              &lt;PatternLayout pattern=&quot;${LOG_PATTERN}&quot;/&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size=&quot;19500KB&quot;/&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  
          &lt;RollingFile name=&quot;infoLog&quot;
                       fileName=&quot;${APP_LOG_ROOT}/info.log&quot;
                       filePattern=&quot;${APP_LOG_ROOT}/InfoLog-%d{yyyy-MM-dd}-%i.log&quot;&gt;
              &lt;LevelRangeFilter minLevel=&quot;INFO&quot; maxLevel=&quot;INFO&quot;
                                onMatch=&quot;ACCEPT&quot; onMismatch=&quot;DENY&quot;/&gt;
              &lt;PatternLayout pattern=&quot;${LOG_PATTERN}&quot;/&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size=&quot;19500KB&quot;/&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  
          &lt;RollingFile name=&quot;warnLog&quot;
                       fileName=&quot;${APP_LOG_ROOT}/warn.log&quot;
                       filePattern=&quot;${APP_LOG_ROOT}/WarnLog-%d{yyyy-MM-dd}-%i.log&quot;&gt;
              &lt;LevelRangeFilter minLevel=&quot;WARN&quot; maxLevel=&quot;WARN&quot;
                                onMatch=&quot;ACCEPT&quot; onMismatch=&quot;DENY&quot;/&gt;
              &lt;PatternLayout pattern=&quot;${LOG_PATTERN}&quot;/&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size=&quot;19500KB&quot;/&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max=&quot;10&quot;/&gt;
          &lt;/RollingFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Logger name=&quot;com.demo.engine&quot; additivity=&quot;false&quot;
                  level=&quot;debug&quot;&gt;
              &lt;AppenderRef ref=&quot;errorlog&quot;/&gt;
              &lt;AppenderRef ref=&quot;debugLog&quot;/&gt;
              &lt;AppenderRef ref=&quot;infoLog&quot;/&gt;
              &lt;AppenderRef ref=&quot;warnLog&quot;/&gt;
          &lt;/Logger&gt;
          &lt;Logger name=&quot;org.springframework&quot; additivity=&quot;false&quot;
                  level=&quot;error&quot;&gt;
              &lt;AppenderRef ref=&quot;springLog&quot;/&gt;
              &lt;AppenderRef ref=&quot;console&quot;/&gt;
          &lt;/Logger&gt;
          &lt;Root level=&quot;DEBUG&quot;&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  <p><strong>Main method :</strong>
  In that below main method i have getting context name using class loader then i put the name using system properties.</p>
  <pre class="lang-java prettyprint-override"><code>public class Main extends SpringBootServletInitializer {
      static {
          String currentpath = &quot;&quot;;
          String logAppContext = &quot;&quot;;
          if (Thread.currentThread().getContextClassLoader().getResource(&quot;&quot;) != null) {
              currentpath = Thread.currentThread().getContextClassLoader().getResource(&quot;&quot;).toString().replace(&quot;%23&quot;, &quot;#&quot;)
                      .replace(&quot;file:/&quot;, &quot;&quot;);
              logAppContext = currentpath.isEmpty() ? logAppContext
                      : Paths.get(currentpath).getParent().getParent().getFileName().toString();
              System.setProperty(&quot;finlog&quot;, logAppContext);
              System.setProperty(&quot;context&quot;, logAppContext);
          }
      }
  
      public static void main(String[] args) {
          SpringApplication.run(Main.class, args);
      }
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Main.class);
      }
  }
  </code></pre>