title: How to create multiple log files in log4j2 using property file?
body: <p>I am using .property file to create log file in specific path but i am creating single file using that. Following is my code of property file:</p>
  
  <pre><code>    status = error
  dest = err
  name = PropertiesConfig
  
  property.filepath= /ap
  property.filename =${filepath}/ai.log
  property.filename1 =${filepath}/file1.log
  property.filename2 =${filepath}/file2.log
  
  filter.threshold.type = ThresholdFilter
  filter.threshold.level = debug
  
  appender.console.type = Console
  appender.console.name = STDOUT
  appender.console.layout.type = PatternLayout
  appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  
  appender.file.type = RollingFile
  appender.file.name = RootFile1
  appender.file.fileName = ${filename}
  appender.file.filePattern = ${filepath}/%d{yyyyMMdd}/cpl.mw.%d{yyyyMMdd}.%i.log.gz
  appender.file.layout.type = PatternLayout
  #appender.file.layout.pattern = %d %p %C{1.} [%t] %m%n
  appender.file.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  appender.file.policies.type = Policies
  appender.file.policies.time.type = TimeBasedTriggeringPolicy
  appender.file.policies.time.interval = 1
  appender.file.policies.time.modulate = true
  appender.file.policies.size.type = SizeBasedTriggeringPolicy
  appender.file.policies.size.size=50MB
  appender.file.strategy.type = DefaultRolloverStrategy
  appender.file.strategy.max = 20
  
  appender.rolling1.type = RollingFile
  appender.rolling1.name = RollingFile1
  appender.rolling1.fileName = ${filename1}
  appender.rolling1.filePattern = ${filepath}/%d{yyyyMMdd}/cpl.mw.%d{yyyyMMdd}.%i.log.gz
  appender.rolling1.layout.type = PatternLayout
  #appender.rolling1.layout.pattern = %d %p %C{1.} [%t] %m%n
  appender.rolling1.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  appender.rolling1.policies.type = Policies
  appender.rolling1.policies.time.type = TimeBasedTriggeringPolicy
  appender.rolling1.policies.time.interval = 1
  appender.rolling1.policies.time.modulate = true
  appender.rolling1.policies.size.type = SizeBasedTriggeringPolicy
  appender.rolling1.policies.size.size=50MB
  appender.rolling1.strategy.type = DefaultRolloverStrategy
  appender.rolling1.strategy.max = 20
  
  
  
  appender.rolling2.type = RollingFile
  appender.rolling2.name = RollingFile2
  appender.rolling2.fileName = ${filename2}
  appender.rolling2.filePattern = ${filepath}/%d{yyyyMMdd}/cpl.mw.%d{yyyyMMdd}.%i.log.gz
  appender.rolling2.layout.type = PatternLayout
  appender.rolling2.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  appender.rolling2.policies.type = Policies
  appender.rolling2.policies.time.type = TimeBasedTriggeringPolicy
  appender.rolling2.policies.time.interval = 1
  appender.rolling2.policies.time.modulate = true
  appender.rolling2.policies.size.type = SizeBasedTriggeringPolicy
  appender.rolling2.policies.size.size=50MB
  appender.rolling2.strategy.type = DefaultRolloverStrategy
  appender.rolling2.strategy.max = 20
  
  loggers
  logger.name=file1
  logger.level = debug
  logger.additivity = true
  logger.appenderRefs = rolling1,stdout
  logger.appenderRefs.level = debug
  logger.appenderRef.rolling1.ref = RollingFile1
  logger.appenderRef.stdout.ref = STDOUT
  
  logger.name=file2
  logger.level = debug
  logger.additivity = true
  logger.appenderRefs = rolling2
  logger.appenderRefs.level = debug
  logger.appenderRef.rolling2.ref = RollingFile2
  </code></pre>
  
  <p>above code is of my xyz.properties file i want to create multiple logs using this configuration file.My property configuration file create multiple file but not put different different logs in log files.I call this from JAVA using below code:</p>
  
  <pre><code>private static final Logger logCommon = LogManager.getLogger("file1");
  private static final Logger logAnalytics = LogManager.getLogger("file2");
  
  public static void main(String[] args) throws Exception {
  
      logCommon.info ("file1 Need it save into commons.log file");
      logAnalytics.info ("file2 Only save into analytics.log file");
  
  }
  </code></pre>
  
  <p><code>2018-01-22 12:52:23 INFO  file2:301 - file2 Only save into analytics.log file</code> log put in both log files.</p>
  
  <p>I refer below links:</p>
  
  <p><a href="https://stackoverflow.com/questions/19052070/log4j2-dynamic-creation-of-log-files-for-multiple-logs">Log4j2: Dynamic creation of log files for multiple logs</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18279656/wildcard-pattern-for-routingappender-of-log4j2">Wildcard pattern for RoutingAppender of Log4j2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/17827923/how-to-write-different-logs-in-different-files-with-log4j2-mdc-in-xml">How to write different logs in different files with log4j2 (MDC in xml)?</a></p>
  
  <p><a href="http://logging.apache.org/log4j/2.x/manual/extending.html" rel="nofollow noreferrer">http://logging.apache.org/log4j/2.x/manual/extending.html</a></p>
  
  <p>i refer below links but not get any solution:</p>
  
  <p><a href="https://stackoverflow.com/questions/32949416/how-to-implement-multi-file-appender-in-log4j2">How to implement multi file appender in log4j2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/31003905/how-to-avoid-multiple-log-files-in-slf4j-logging">How to avoid multiple log files in slf4j logging?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/38053283/log4j2-generate-application-specific-log-files-in-weblogic">log4j2 - generate application specific log files in weblogic</a></p>
  
  <p><a href="https://stackoverflow.com/questions/47285254/how-to-create-multiple-log-files-of-different-content-with-log4j">How to create multiple log files of different content with log4j</a></p>
  
  <p><a href="https://stackoverflow.com/questions/36076316/using-properties-in-log4j2-yaml">enter link description here</a></p>
  
  <p><a href="https://stackoverflow.com/questions/39649383/log4j2-keyvaluepair-for-properties-file">log4j2 KeyValuePair for .properties file</a></p>
  
  <p><a href="https://stackoverflow.com/questions/24205093/how-to-create-a-custom-appender-in-log4j2">How to Create a Custom Appender in log4j2?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/46600724/configuring-async-loggers-in-log4j2-properties">Configuring async loggers in log4j2.properties</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30247323/how-to-create-custom-rewritepolicy-in-log4j2">How to create custom RewritePolicy in log4j2?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32995946/how-to-set-the-log-level-on-a-class-in-log4j2-properties">How to set the log level on a class in log4j2 properties</a></p>
  
  <p><a href="https://stackoverflow.com/questions/43406603/increasing-file-indexing-on-onstartuptriggeringpolicy-in-log4j2">Increasing file indexing on OnStartupTriggeringPolicy in log4j2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/47869975/how-to-configure-log-file-path-to-current-working-target-directory-in-log4j2-xml">how to configure log file path to current working target directory in log4j2 xml format</a></p>
  
  <p><a href="https://stackoverflow.com/questions/28215119/how-to-configure-resttemplate-debug-logging-in-log4j2-xml">How to configure RestTemplate debug logging in log4j2 xml</a></p>
  
  <p><a href="https://stackoverflow.com/questions/7137850/creating-multiple-log-files-in-iphone-app">Creating multiple log files in iPhone app</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32499188/log4j2-using-multiple-appender-and-logger">Log4j2 using multiple appender and logger</a></p>
  
  <p><a href="https://stackoverflow.com/questions/46336225/how-to-create-multiple-log-file-programatically-in-log4j2">How to create multiple log file programatically in log4j2?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/46336225/how-to-create-multiple-log-file-programatically-in-log4j2">How to create multiple log file programatically in log4j2?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/26508300/how-to-specify-log-file-in-log4j2">How to specify log file in log4j2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/44287020/log-separate-log-levels-to-separate-files-in-log4j2-properties-file">Log separate log levels to separate files in log4j2 properties file</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30910176/unable-to-create-multiple-log-files-based-on-the-threadcontext-map-values-using">Unable to create multiple log files based on the ThreadContext map values using routing appender in log4j2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/41669056/how-to-create-custom-rolling-file-appender-in-log4j2-customized-file-name">How to create Custom Rolling File appender in log4j2 - customized file name</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19976211/different-log-files-for-multiple-threads-using-log4j2">Different log files for multiple threads using log4j2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/47717645/log4j2-yaml-generate-multiple-log-files-issue">Log4j2 YAML generate multiple log files issue</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27941144/how-to-create-multiple-log-files-using-log4j">How to create multiple log files using log4j</a></p>
  
  <p><a href="https://stackoverflow.com/questions/47332241/log4j2-overriding-log-file-programmatically">Log4j2 - Overriding log file programmatically</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30412710/how-to-create-a-rolling-file-appender-plugin-in-log4j2">How to create a rolling file appender plugin in log4j2</a></p>