log4j2 - JVM input arguments lookup (jvmrunargs) does not work
<p>I have just started trying out log4j2 (I've been using log4j 1.2.X previously). Aside from the frustration of trying to figure out what is needed/valid for the configuration file (log4j2.xml), I have been unable to use the Java VM "lookup" capability supposedly supported by log4j2. As far as I can tell, I'm doing the right stuff - based on the information available from the log4j web site. Has anyone ever had any success with this?</p>

<p>Here are the basics of what I'm doing:</p>

<p>java class:
[which is using SLF4J to "bridge" to log4j]</p>

<pre><code>package logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {

  private static final Logger logger = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args) {
    logger.info("In main()");
  }

}
</code></pre>

<p>log4j2.xml:
[I'm trying to pass a log directory, configured elsewhere]</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;configuration status="INFO" strict="true"&gt;
  &lt;Properties&gt;
    &lt;Property name="filename"&gt;${jvmrunargs:log_dir}/log.txt&lt;/Property&gt;
  &lt;/Properties&gt;

  &lt;!-- APPENDERS --&gt;
  &lt;Appenders&gt;
    &lt;Appender type="File" name="File" fileName="${filename}"&gt;
      &lt;Layout type="PatternLayout"&gt;
        &lt;Pattern&gt;%d %p %C{1.} [%t] %m%n&lt;/Pattern&gt;
      &lt;/Layout&gt;
    &lt;/Appender&gt;
  &lt;/Appenders&gt;

  &lt;!-- LOGGERS --&gt;
  &lt;Loggers&gt;
    &lt;Root level="INFO"&gt;
      &lt;AppenderRef ref="File" /&gt;
    &lt;/Root&gt;
  &lt;/Loggers&gt;
&lt;/configuration&gt;
</code></pre>

<p>This fails with multiple exceptions thrown by log4j:</p>

<pre><code>SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/jo24447/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/jo24447/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
2016-12-07 10:44:52,566 main ERROR FileManager (${jvmrunargs:log_dir}/log.txt) java.io.FileNotFoundException: ${jvmrunargs:log_dir}\log.txt (The filename, directory name, or volume label syntax is incorrect) java.io.FileNotFoundException: ${jvmrunargs:log_dir}\log.txt (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:221)
    at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:258)
    at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:238)
    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.FileManager.getFileManager(FileManager.java:110)
    at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:89)
    at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:51)
    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:942)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:603)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:103)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
    at logger.Main.&lt;clinit&gt;(Main.java:8)

2016-12-07 10:44:52,572 main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.FileAppender, element File. java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory@1decca33] unable to create manager for [${jvmrunargs:log_dir}/log.txt] with data [org.apache.logging.log4j.core.appender.FileManager$FactoryData@24cee99e]
    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.FileManager.getFileManager(FileManager.java:110)
    at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:89)
    at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:51)
    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:942)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:603)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:103)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
    at logger.Main.&lt;clinit&gt;(Main.java:8)

2016-12-07 10:44:52,575 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.FileAppender for element File. java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.FileAppender
    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:942)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:603)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:103)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
    at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
    at logger.Main.&lt;clinit&gt;(Main.java:8)

2016-12-07 10:44:52,576 main ERROR Null object returned for File in Appenders.
2016-12-07 10:44:52,581 main ERROR Unable to locate appender "File" for logger config "root"
</code></pre>

<p>Here is the simple pom.xml:</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;logger&lt;/groupId&gt;
  &lt;artifactId&gt;logger&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;

  &lt;properties&gt;
    &lt;compileSource&gt;1.7&lt;/compileSource&gt;

    &lt;maven-compiler-plugin.version&gt;2.3.2&lt;/maven-compiler-plugin.version&gt;
    &lt;maven-jar-plugin.version&gt;2.5&lt;/maven-jar-plugin.version&gt;
    &lt;maven-dependency-plugin.version&gt;2.10&lt;/maven-dependency-plugin.version&gt;

    &lt;log4j.version&gt;2.7&lt;/log4j.version&gt;
    &lt;slf4j.version&gt;1.7.21&lt;/slf4j.version&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;
    &lt;!-- Apache Log4J 2 --&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;${log4j.version}&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;${log4j.version}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;!-- Log4J 2 to SLF4J bridge --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j-slf4j-impl&lt;/artifactId&gt;
      &lt;version&gt;${log4j.version}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;!-- SLF4J --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
      &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
      &lt;version&gt;${slf4j.version}&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;${maven-compiler-plugin.version}&lt;/version&gt;
        &lt;configuration&gt;
          &lt;source&gt;${compileSource}&lt;/source&gt;
          &lt;target&gt;${compileSource}&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;

&lt;/project&gt;
</code></pre>