Using Log4j2 in a bundle causes following error:
ERROR StatusLogger org.apache.logging.log4j.core.impl.Log4jContextFactory does not implement org.apache.logging.log4j.spi.LoggerContextFactory
ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger
printing the ClassLoaders in LogManager gives me following output:
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api 
org.apache.logging.log4j.core.impl.Log4jContextFactory loaded by sun.misc.Launcher$AppClassLoader@35a16869
We have two different ClassLoaders. That's why the implementation is not assignable. The core uses the bootstrap-classloader and the api uses the bundle-classloader.
Workaround needed. Thx
ProviderUtil.findClassLoader() returns the bootstrap-classloader but not the bundle-classloader of the log4j2-core. The log4j2-core is a fragment of the log4j2-api bundle. Thus, ProviderUtil.findClassLoader() must return the bundle-classloader of log4j2-api. This a bug for the case that log4j2-core is used as the implementation. There are other cases that will also cause problems. Further investigations are necessary.
1. check if log4j2 runs in an OSGI container.
Bundle mybundle = org.osgi.framework.FrameworkUtil.getBundle(MyClass.this);
2. if(mybundle != null), than get bundle-classloader of log4j2-impl.