As clearly indicated in the Log4j support page, please use mailing lists for questions!
Up until version 2.20.0, I was able to use following method to check the version #.
org.apache.logging.log4j.LogManager.class.getPackage().getImplementationVersion()
Starting version 2.21.1 the above method returns null as I could not find "Implementation-Version" entry in the MANIFEST.MF file.