title: log4j custom appender stop method not getting called
body: <p>I am trying to implement a custom log appender for log4j and will need to initialize some resources before start and cleanup at the end. Somehow my stop method will not be executed.
  I've tried using <code> LogManager.shutdown();</code> but I cannot see my method getting called.</p>
  <p>This is my appender class:</p>
  <pre><code>@Plugin(name = &quot;CELogAppender&quot;, category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
  public class CELogAppender extends AbstractAppender {
      private final ConcurrentMap&lt;String, LogEvent&gt; eventMap = new ConcurrentHashMap&lt;&gt;();
  
      protected CELogAppender(String name, Filter filter, Layout&lt;? extends Serializable&gt; layout,
                              boolean ignoreExceptions, Property[] properties) {
          super(name, filter, layout, ignoreExceptions, properties);
          System.out.println(&quot;new celogappender&quot;);
      }
  
      public static CELogAppender createAppender(@PluginAttribute(&quot;name&quot;) String name,
                                                 @PluginAttribute(&quot;Filter&quot;) Filter filter,
                                                 @PluginAttribute(&quot;Layout&quot;) Layout&lt;? extends Serializable&gt; layout) {
          return new CELogAppender(name, filter, layout, false, null);
      }
  
      @Override
      public void append(LogEvent event) {
          eventMap.put(Instant.now().toString(), event);
          System.out.println(&quot;event added&quot;);
      }
  
      public ConcurrentMap&lt;String, LogEvent&gt; getEvents() {
          return eventMap;
      }
  
      @Override
      public void start() {
          super.start();
          System.out.println(&quot;start appender&quot;);
      }
  
      @Override
      public void stop() {
          super.stop();
          System.out.println(&quot;stop appender&quot;);
      }
  }
  </code></pre>
  <p>And this is a simple test</p>
  <pre><code>public class CELogAppenderTests {
      private static Logger logger;
      private static CELogAppender ceLogAppender;
  
      @BeforeAll
      public static void setup() {
          logger = LogManager.getLogger(CELogAppenderTests.class.getName());
          LoggerContext loggerContext = LoggerContext.getContext(false);
          Configuration config = loggerContext.getConfiguration();
          PatternLayout layout = PatternLayout.newBuilder()
                  .withPattern(&quot;%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n&quot;)
                  .build();
          ceLogAppender = CELogAppender.createAppender(&quot;CELogAppender&quot;, null, layout);
          ceLogAppender.start();
          config.addAppender(ceLogAppender);
  
  
          AppenderRef appenderRef = AppenderRef.createAppenderRef(&quot;CELogAppender&quot;, null, null);
          AppenderRef[] appenderRefs = new AppenderRef[]{appenderRef};
          LoggerConfig loggerConfig = LoggerConfig.createLogger(false, Level.ALL,
                  CELogAppenderTests.class.getName(), &quot;true&quot;, appenderRefs, null, config, null);
  
          loggerConfig.addAppender(ceLogAppender, null, null);
          config.addLogger(CELogAppenderTests.class.getName(), loggerConfig);
          loggerContext.updateLoggers();
      }
  
      @Test
      public void testAppenderNotEmpty() {
          logger.info(&quot;A message&quot;);
          assertFalse(ceLogAppender.getEvents().isEmpty());
      }
  
      @AfterAll
      public static void shutdown() {
          System.out.println(&quot;shutdown&quot;);
          LogManager.shutdown();
      }
  }
  </code></pre>
  <p>I can see the console output</p>
  <pre><code>new celogappender
  start appender
  event added
  shutdown
  </code></pre>
  <p>but I am missing the output from my stop method:</p>
  <pre><code>    @Override
      public void stop() {
          super.stop();
          System.out.println(&quot;stop appender&quot;);
      }
  </code></pre>