} catch (final Exception ex) {
// Invalid source location.
}
final LoggerContextFactory f = LogManager.getFactory();
if (f instanceof Log4jContextFactory) {
Log4jContextFactory factory = (Log4jContextFactory) f;
final org.apache.logging.log4j.spi.LoggerContext context = factory.getContext(Configurator.class.getName(),
loader, externalContext, false, source);
if (context instanceof LoggerContext) {
return (LoggerContext) context;
} else {
LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j",