How to add appender to Logger in Log4j2
<p>In Log4j 1.2, you could simply take a logger and add an appender at runtime. This was handy for test purposes for instance. We used to create a mock appender and add it to the logger. Subsequently we could make different assertions.</p>

<p>What is the equivalent thing with log4j2?</p>

<p>This <a href="https://stackoverflow.com/questions/3717402/how-to-test-w-junit-that-warning-was-logged-w-log4j">example</a> for instance shows how other people were adding test appenders.</p>

<p>The <a href="https://logging.apache.org/log4j/2.x/manual/customconfig.html" rel="noreferrer">log4j2</a> page shows a few examples on how to add appenders. However, they add appenders to the overall context. Which seems different from adding appenders for one specific logger. </p>

<p>Another observation is that if you use org.apache.logging.log4j.core.Logger as opposed to org.apache.logging.log4j.Logger, you can still add appenders. However most people use org.apache.logging.log4j.Logger. And in fact, LogManager returns an instance of org.apache.logging.log4j.Logger. So, I am not sure how to connect these two classes and whether they should be connected at all.</p>

<p>Another observation is that if I call</p>

<pre><code>      LogManager.getContext().getConfiguration().getLoggers()
</code></pre>

<p>I can get a ist of all LoggerConfig objects in the context. I subsequently add appenders to any LoggerConfig object. The question however is, how do I get the LoggerConfig related to an instance of  org.apache.logging.log4j.Logger? </p>

<p>This is confusing me.</p>