title: Spring boot log4j2 properties Configuring
body: <p>Am trying to configuring Log4j2 to log my all logger in an external file so I using spring boot log4j2  </p>
  
  <p>i also use Log4J4 Maven Dependencies </p>
  
  <p>i checked so many website they also duing same but  don't know what i missing here please help </p>
  
  <p>thanks </p>
  
  <p><strong><em>Pom.xml file</em></strong> </p>
  
  <pre><code> &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
          &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
          &lt;groupId&gt;eta&lt;/groupId&gt;
          &lt;artifactId&gt;eta_gtc_core&lt;/artifactId&gt;
          &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
          &lt;packaging&gt;pom&lt;/packaging&gt;
          &lt;modules&gt;
              &lt;module&gt;eta-core-domain-api&lt;/module&gt;
              &lt;module&gt;eta-core-dao-api&lt;/module&gt;
              &lt;module&gt;eta-core-dao-impl&lt;/module&gt;
              &lt;module&gt;eta-core-web&lt;/module&gt;
              &lt;module&gt;eta-core-domain-impl&lt;/module&gt;
              &lt;module&gt;eta-core-services-api&lt;/module&gt;
              &lt;module&gt;eta-core-services-impl&lt;/module&gt;
  
              &lt;module&gt;
                  ../../../../../GIT_CLONE_MAT_JAVA_23_JULY/Eta-int-mat-java/SourceCode/JavaSourceCode/eta-common-util
              &lt;/module&gt;
          &lt;/modules&gt;
  
          &lt;parent&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
              &lt;version&gt;1.5.10.RELEASE&lt;/version&gt;
              &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
          &lt;/parent&gt;
  
          &lt;properties&gt;
              &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
              &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
              &lt;spring-cloud.version&gt;Dalston.SR2&lt;/spring-cloud.version&gt;
              &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;/properties&gt;
          &lt;dependencies&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
                  &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;/dependency&gt;
  
              &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;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;mysql&lt;/groupId&gt;
                  &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.modelmapper&lt;/groupId&gt;
                  &lt;artifactId&gt;modelmapper&lt;/artifactId&gt;
                  &lt;version&gt;1.1.0&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&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;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;version&gt;2.5&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.5&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.json&lt;/groupId&gt;
                  &lt;artifactId&gt;json&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
                  &lt;artifactId&gt;jjwt&lt;/artifactId&gt;
                  &lt;version&gt;0.9.0&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;junit&lt;/groupId&gt;
                  &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
                  &lt;scope&gt;compile&lt;/scope&gt;
              &lt;/dependency&gt;
  
          &lt;/dependencies&gt;
          &lt;dependencyManagement&gt;
              &lt;dependencies&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                      &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                      &lt;type&gt;pom&lt;/type&gt;
                      &lt;scope&gt;import&lt;/scope&gt;
                  &lt;/dependency&gt;
              &lt;/dependencies&gt;
          &lt;/dependencyManagement&gt;
      &lt;/project&gt;
  </code></pre>
  
  <p><strong><em>Application.properties File.</em></strong></p>
  
  <pre><code>server.port=8080
  eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
  logging.config=src/main/resources/log4j2.properties
  </code></pre>
  
  <p><strong><em>log4j2.properties</em></strong></p>
  
  <pre><code>name=PropertiesConfig
  property.filename = logs
  appenders = console, file
  appender.console.type = Console
  appender.console.name = STDOUT
  appender.console.layout.type = PatternLayout
  appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
  appender.file.type = File
  appender.file.name = LOGFILE
  appender.file.fileName=D:/core_log/eta_core_web.log
  appender.file.layout.type=PatternLayout
  appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
  loggers=file
  logger.file.name=com.gtc.eta.core.rest
  logger.file.level = debug
  logger.file.appenderRefs = file
  logger.file.appenderRef.file.ref = LOGFILE
  rootLogger.level = debug
  rootLogger.appenderRefs = stdout
  rootLogger.appenderRef.stdout.ref = STDOUT
  logger.file.additivity = false
  log4j.appender.console.immediateFlush=true
  </code></pre>
  
  <p><strong><em>Spring boot Start Class</em></strong> </p>
  
  <pre><code>import org.springframework.boot.SpringApplication;
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.autoconfigure.domain.EntityScan;
  import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  
  
  @EnableDiscoveryClient
  @SpringBootApplication
  public class CoreStart {
       private static final Logger LOGGER = LogManager.getLogger(CoreStart.class);
      public static void main(String[] args) {
          SpringApplication.run(CoreStart.class, args);
  
          LOGGER.info("Info level log message");
          LOGGER.debug("Debug level log message");
          LOGGER.error("Error level log message");
      }
  }
  </code></pre>
  
  <p><strong><em>Error Code</em></strong></p>
  
  <pre><code>Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
  Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/LoggerContext;Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:176)
      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadDefaults(Log4J2LoggingSystem.java:159)
      at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:84)
      at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:59)
      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:148)
      at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:303)
      at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
      at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
      at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
      at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
      at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
      at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
      at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
      at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:175)
      at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:98)
      at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:64)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
      at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
      at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
      at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
      at com.gtc.eta.core.CoreStart.main(CoreStart.java:28)
      ... 5 more
  </code></pre>