title: Unable to get log4j to write to log files when using Tomcat 9
body: <p>I am setting up a web app running on Tomcat 9.</p>
  <p>To match code written elsewhere, we want to keep using log4j for the code in the web application.</p>
  <p>I have the following defined in my build.gradle</p>
  <pre><code>implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.3'
  implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
  runtimeOnly group: 'org.apache.logging.log4j', name: 'log4j-web', version: '2.13.3'
  </code></pre>
  <p>And both <code>log4j-api-2.13.3.jar</code>, <code>log4j-core-2.13.3.jar</code> and <code>log4j-web-2.13.3.jar</code> are present in WEB-INF/libs under my webapp folder.</p>
  <p>My log4j configuration is in  <code>WEB-INF/classes/log4j.properties</code></p>
  <pre><code># Root logger option
  log4j.rootLogger=DEBUG, file
  
  # Direct log messages to a log file
  log4j.appender.file=org.apache.log4j.RollingFileAppender
  
  #Redirect to Tomcat logs folder
  log4j.appender.file.File=${catalina.base}/logs/my-application.log
  
  log4j.appender.file.MaxFileSize=10MB
  log4j.appender.file.MaxBackupIndex=10
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  </code></pre>
  <p>In my handler I create the logger and tries to log some info, but it does not show up anywhere.</p>
  <pre><code>
  @WebServlet(name = &quot;MyServlet&quot;, urlPatterns = {&quot;/test&quot;}, loadOnStartup = 1)
  public class MyServletextends HttpServlet {
      private static final Logger logger = LogManager.getLogger(MyServlet.class);
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
          logger.info(&quot;Test&quot;);
          response.getWriter().print(&quot;Service is up and running!&quot;);
      }
  }
  
  </code></pre>
  <p>In the <code>localhost.2020-09-28.log</code> logfile I get a message saying</p>
  <pre><code>28-Sep-2020 11:38:18.391 FINE [main] org.apache.catalina.core.StandardContext.filterStart  Starting filter 'log4jServletFilter'
  </code></pre>
  <p>So I assume that log4j is loaded correctly, at least I do not find any errors in any of the log files.</p>
  <p>What configuration am I missing for being able to use log4j, and have it output to its own file?</p>