title: Logging : Log4j2 Implementation using Properties file in Spring Boot
body: <p>I am using Spring Boot and log4j2 for my logging because I want my logs to be written on a file instead of console. So I have implemented log4j2.properties and kept in under resource folder in Spring Boot project.</p>
  
  <p>When I start Spring Boot application, I couldn't see the log file and logs.</p>
  
  <p>if added below configuration in application.properties then logs are not getting in console and in file.</p>
  
  <pre><code>logging.config=classpath:log4j2.properties
  </code></pre>
  
  <p>but added console and file appenders in log4j2.properties file.</p>
  
  <p>below are the details:</p>
  
  <h1>log4j2.properties</h1>
  
  <pre><code># Root logger option
  log4j.rootLogger=INFO, file, DEBUG, stdout
  
  
  # configuration to print into file
  log4j.appender.file=org.apache.log4j.RollingFileAppender
  log4j.appender.file.File=C:/Logs/app.log
  log4j.appender.file.MaxFileSize=12MB
  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
  
  
  # configuration to print on console
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  </code></pre>
  
  <h1>DemoApplication.java</h1>
  
  <pre><code>@SpringBootApplication
  public class DemoApplication extends SpringBootServletInitializer {
  
    private final static Logger log = LogManager.getLogger(DemoApplication.class);
  
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  
      return application.sources(DemoApplication.class);
    }
  
    public static void main(String[] args) {
  
      SpringApplication.run(DemoApplication.class, args);
      log.info("**** Demo Application Started *****");
  
    }
  
  }
  </code></pre>
  
  <h1>POM.XML</h1>
  
  <pre><code>&lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
           &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
        &lt;/dependency&gt;
  
        &lt;!--Logging--&gt;
        &lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
           &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
           &lt;exclusions&gt;
              &lt;exclusion&gt;
                 &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                 &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
           &lt;/exclusions&gt;
        &lt;/dependency&gt;
  
        &lt;!--https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j--&gt;
        &lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
           &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
        &lt;/dependency&gt;
  
        &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-api&lt;/artifactId&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;/dependency&gt;
  </code></pre>
  
  <p>Can anyone please help me on this.</p>