AddAppender programmatically in a proper way

Thomas Hartwig <[email protected]> Fri, 21 Oct 2022 11:09:24 +0200
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>
I want to add a customized Appender to Log4J 2.x. However there is no 
clear API to use it.

Right now I am using:

((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).addAppender(new 
MyAppender());

This is working, however the API states this:

This method is not exposed through the public API and is used primarily 
for unit testing.

There are a couple of examples in the net where it might be added 
different, but no on is referring to an "official" way.

What is the preferred way of adding such an Appender?