I think adding another check for ```org.apache.log4j.spi.LoggerContext``` would be a better solution here.

```java
Class.forName("org.apache.logging.log4j.LogManager", true, cl);
// check for the logger context 
Class.forName("org.apache.log4j.spi.LoggerContext", true, cl);
LoggerProvider provider = new Log4j2LoggerProvider();
```