title: Log4J2 Relative path
body: <p>I have problem with saving log file in Log4j2.</p>
  <p>When I describe absolute path to directory for RollingFile within my project like &quot;C:\Users\myuser\eclipse-workspace\app\src\main\resources\logs&quot;, file is succesfully creating, all logs are recording.</p>
  <p>When I describe relative path to directory like &quot;./logs/trace.txt&quot;, I get the error written below, though it is basically the same directory. It happens even if I set &quot;fileName&quot; just like &quot;trace.txt&quot; without any paths.</p>
  <p>How to fix it? Maybe it connected to the fact it is a web project deploying on Tomcat...</p>
  <pre><code>    2020-08-11 14:35:40,267 localhost-startStop-1 ERROR Unable to create file trace_11_08_2020.log java.io.IOException: Access denied
      at java.io.WinNTFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(File.java:1012)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:574)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:554)
      at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:112)
      at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:155)
      at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:131)
      at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
      at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
      at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
      at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:239)
      at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:159)
      at org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi(Log4jWebInitializerImpl.java:174)
      at org.apache.logging.log4j.web.Log4jWebInitializerImpl.start(Log4jWebInitializerImpl.java:112)
      at org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:57)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  
  2020-08-11 14:35:40,283 localhost-startStop-1 ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.RollingFileAppender, element RollingFile. java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory@81d52be] unable to create manager for [trace_11_08_2020.log] with data [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$FactoryData@3d033b58[pattern=trace_11_08_2020.log.zip, append=true, bufferedIO=true, bufferSize=8192, policy=CompositeTriggeringPolicy(policies=[SizeBasedTriggeringPolicy(size=10485760)]), strategy=DefaultRolloverStrategy(min=1, max=42, useMax=true), advertiseURI=null, layout=%d{HH:mm:ss.SSS} [%-21t] %-5level{ERROR=***ERROR***} %-10marker %l - %m%n]]
      at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:114)
      at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:155)
      at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:131)
      at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
      at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
      at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
      at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:239)
      at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:159)
      at org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi(Log4jWebInitializerImpl.java:174)
      at org.apache.logging.log4j.web.Log4jWebInitializerImpl.start(Log4jWebInitializerImpl.java:112)
      at org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:57)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  
  2020-08-11 14:35:40,289 localhost-startStop-1 ERROR Unable to invoke factory method in class 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
      at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:224)
      at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:130)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
      at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
      at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:239)
      at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:159)
      at org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi(Log4jWebInitializerImpl.java:174)
      at org.apache.logging.log4j.web.Log4jWebInitializerImpl.start(Log4jWebInitializerImpl.java:112)
      at org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:57)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  <p>My log4j2 configuration:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Configuration status=&quot;WARN&quot;&gt;
    &lt;Properties&gt;
      &lt;Property name=&quot;rootpath&quot;&gt;&lt;/Property&gt;
    &lt;/Properties&gt;
    
    &lt;CustomLevels&gt;
      &lt;CustomLevel name=&quot;HTTP&quot; intLevel=&quot;50&quot; /&gt;
    &lt;/CustomLevels&gt;
    
    &lt;Appenders&gt;
    
      &lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;
        &lt;PatternLayout pattern=&quot;%d{HH:mm:ss.SSS} [%-21t] %-5level %-10marker %l - %m%n&quot;/&gt;
      &lt;/Console&gt;
      
      &lt;RollingFile name=&quot;FileTrace&quot; ignoreExceptions=&quot;false&quot; fileName=&quot;${rootpath}trace_${date:dd_MM_yyyy}.log&quot; filePattern=&quot;${rootpath}trace_${date:dd_MM_yyyy}.log.zip&quot;&gt;
        &lt;PatternLayout pattern=&quot;%d{HH:mm:ss.SSS} [%-21t] %-5level{ERROR=***ERROR***} %-10marker %l - %m%n&quot;/&gt;
        &lt;Policies&gt;
          &lt;SizeBasedTriggeringPolicy size=&quot;10 MB&quot;/&gt;
        &lt;/Policies&gt;
        &lt;DefaultRolloverStrategy max=&quot;42&quot; /&gt;
      &lt;/RollingFile&gt;
      
      &lt;RollingFile name=&quot;FileError&quot; ignoreExceptions=&quot;false&quot; fileName=&quot;${rootpath}error_trace_${date:dd_MM_yyyy}.log&quot; filePattern=&quot;${rootpath}error_trace_${date:dd_MM_yyyy}.log.zip&quot;&gt;
        &lt;PatternLayout pattern=&quot;%d{HH:mm:ss.SSS} [%-21t] %-5level %l %rEx{full} %n&quot;/&gt;
        &lt;Policies&gt;
          &lt;SizeBasedTriggeringPolicy size=&quot;10 MB&quot;/&gt;
        &lt;/Policies&gt;
        &lt;DefaultRolloverStrategy max=&quot;42&quot; /&gt;
        &lt;ThresholdFilter level=&quot;HTTP&quot; onMatch=&quot;DENY&quot; onMismatch=&quot;NEUTRAL&quot;/&gt;
      &lt;/RollingFile&gt;
      
      &lt;RollingFile name=&quot;FileHTTP&quot; ignoreExceptions=&quot;false&quot; fileName=&quot;${rootpath}http_trace_${date:dd_MM_yyyy}.log&quot; filePattern=&quot;${rootpath}http_trace_${date:dd_MM_yyyy}.log.zip&quot;&gt;
        &lt;PatternLayout pattern=&quot;%d{HH:mm:ss.SSS} [%-21t] %-5level %-10marker - %m%n&quot;/&gt;
        &lt;Policies&gt;
          &lt;SizeBasedTriggeringPolicy size=&quot;10 MB&quot;/&gt;
        &lt;/Policies&gt;
        &lt;DefaultRolloverStrategy max=&quot;42&quot; /&gt;
        &lt;ThresholdFilter level=&quot;HTTP&quot; onMatch=&quot;ACCEPT&quot; onMismatch=&quot;DENY&quot;/&gt;
      &lt;/RollingFile&gt;
      
    &lt;/Appenders&gt;
    
    &lt;Loggers&gt;
      &lt;Root level=&quot;ALL&quot;&gt;
        &lt;AppenderRef ref=&quot;FileTrace&quot; level=&quot;TRACE&quot;/&gt;
        &lt;AppenderRef ref=&quot;FileError&quot; level=&quot;ERROR&quot;/&gt;
        &lt;AppenderRef ref=&quot;FileHTTP&quot; level=&quot;HTTP&quot;/&gt;
      &lt;/Root&gt;
    &lt;/Loggers&gt;
    
  &lt;/Configuration&gt;
  </code></pre>
  <p>My log4j2 dependencies:</p>
  <pre><code>&lt;dependency&gt;
               &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
               &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
               &lt;version&gt;2.8.2&lt;/version&gt;
          &lt;/dependency&gt;
              
          &lt;dependency&gt;
               &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
               &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
               &lt;version&gt;2.8.2&lt;/version&gt;
          &lt;/dependency&gt;
          
            &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-web&lt;/artifactId&gt;
              &lt;version&gt;2.13.3&lt;/version&gt;
            &lt;/dependency&gt;
  </code></pre>