Okay, I understand the issue now.
Yes, if all loggers are made asynchronous by setting Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector, the loggerContext name is "AsyncLoggerContext" for all web apps. This name is set in the AsyncLoggerContextSelector class.
We can make this name unique by appending the hashCode of the AsyncLoggerContextSelector class. I believe that should resolve the issue.
As a side note: please be aware that making all loggers async only works correctly with web applications if you bundle the log4j2 jar files in WEB-INF/lib in your war file. (See
Meanwhile, the quickest way for you to resolve this is to configure log4j2 differently:
- remove the Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector setting
- and, in your log4j2.json configuration, use AsyncRoot and AsyncLogger instead of Root and Logger. This also makes the loggers asynchronous, giving you the same performance benefits, but uses a different mechanism under the hood. This way, the LoggerContext will be assigned a unique name by the web container.
I'm beginning to think we should update the documentation to recommend that web applications should avoid the use of Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector and instead configure with AsyncRoot and AsyncLogger to avoid these issues...