我已经将log4j2.properties
定义为
...
appender.async.type = Async
appender.async.name = async
appender.async.appenderRefs.type = AppenderRefs
appender.async.appenderRefs.consoleAppender.type = AppenderRef
appender.async.appenderRefs.consoleAppender.ref = console
rootLogger.level = debug
rootLogger.appenderRef.console.ref = async
rootLogger.appenderRef.rolling.ref = rolling
运行时异常:
2019-06-28 12:03:27,996 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.AsyncAppender for element Async: java.lang.NullPointerException java.lang.NullPointerException
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:52)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:180)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:964)
...
2019-06-28 12:03:27,997 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.AsyncAppender for element Async: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.AsyncAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.AsyncAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:234)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:134)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:964)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:904)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:896)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
我想念的是什么?
最佳答案
尝试以下配置-
appender.async.type = Async
appender.async.name = asyncAppender
appender.async.appenderRef.type = AppenderRef
appender.async.appenderRef.ref = consoleAppender