title: How to programatically configure appenders or initialize logging in log4j2?
body: <p>I have been trying to configure appender programatically, but not getting success so far.
  i just want to configure appender without file so that it can send logs to console or file.</p>
  
  <pre><code>    String PATTERN = "%d [%p|%c|%C{1}] %m%n";
      PatternLayout layout = PatternLayout.createLayout(PATTERN, null, null,
              null, null, null);
      ConsoleAppender console = ConsoleAppender.createAppender(layout, null,
              null, "console", "true", "true"); // create appender
  
      AppenderRef appender = AppenderRef.createAppenderRef("console",
              "DEBUG", null);
  
      logger = (Logger) LogManager.getLogger(InitLogger.class);
      LoggerContext context = logger.getContext();
      BaseConfiguration configuration =(BaseConfiguration) context.getConfiguration();
      configuration.addAppender(console);
      logger.addAppender(configuration.getAppender("console"));
  </code></pre>