title: logback add appendar Programmatically
body: <p>i want to logappendar Programmatically , but this code is not correcty work</p>
  
  <p>this is my configuration code...</p>
  
  <pre><code>public enum Logger {
      INSTANCE;
  
      Logger logger;
      LoggerContext loggerContext;
  
      public final String CONSOLE_APPENDER_NAME="CONSOLE_";
      public final String FILE_APPENDER_NAME="FILE_";
      public final String LOGGER_NAME="LOGGER";
      public final String LOG_FILE_NAME="log.log";
  
      Logger(){
          loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
  
          String patternRf = "%d{HH:mm:ss} %-5level [%thread] %logger{36} - %msg%n";
          PatternLayoutEncoder encoder = new PatternLayoutEncoder();
          encoder.setPattern(patternRf);
          encoder.setContext(loggerContext);
          encoder.start();
  
          ConsoleAppender&lt;ILoggingEvent&gt; soutAppender = new ConsoleAppender&lt;ILoggingEvent&gt;();
          soutAppender.setName(CONSOLE_APPENDER_NAME);
          soutAppender.setEncoder(encoder);
  
          loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).detachAndStopAllAppenders();
          logger = loggerContext.getLogger(LOGGER_NAME);
          logger.detachAndStopAllAppenders();
  
  
          IPath logDirPath = new Path("/log");
          File logDir = new File(logDirPath.toOSString());
          if(!logDir.exists()){
              logDir.mkdir();
          }
          RollingFileAppender&lt;ILoggingEvent&gt; rfAppender = rollingFileLog(logDirPath, loggerContext, encoder);
  
          rfAppender.start();
          soutAppender.start();
  
          logger.addAppender(soutAppender);
          logger.addAppender(rfAppender);
  
      }
  
      private RollingFileAppender&lt;ILoggingEvent&gt; rollingFileLog(IPath logDirPath, LoggerContext loggerContext, PatternLayoutEncoder encoder) {
          RollingFileAppender&lt;ILoggingEvent&gt; logFileAppender = new RollingFileAppender&lt;ILoggingEvent&gt;();
          logFileAppender.setContext(loggerContext);
          logFileAppender.setName(FILE_APPENDER_NAME);
          logFileAppender.setEncoder(encoder);
          logFileAppender.setAppend(true);
          logFileAppender.setFile(logDirPath.append(LOG_FILE_NAME).toOSString());
  
          TimeBasedRollingPolicy&lt;ILoggingEvent&gt; logFilePolicy = new TimeBasedRollingPolicy&lt;ILoggingEvent&gt;();
          logFilePolicy.setContext(loggerContext);
          logFilePolicy.setParent(logFileAppender);
          logFilePolicy.setFileNamePattern("./log/%d{yyyy,aux}/%d{MM,aux}/%d{dd,aux}/service_rolling.log.%d{yyyy-MM-dd_hhmmss}");
          logFilePolicy.setMaxHistory(7);
          logFilePolicy.start();
  
          logFileAppender.setRollingPolicy(logFilePolicy);
  
          return logFileAppender;
      }   
  
      public void debug(String msg){
          logger.debug(msg);
      }
  
  
  
  }
  </code></pre>
  
  <p>and this is my test code</p>
  
  <pre><code>public class test {
      public static void main(String[] args) {
          Logger.INSTANCE.debug("a");
          Logger.INSTANCE.debug("b");
          Logger.INSTANCE.debug("c");
          Logger.INSTANCE.debug("d");
          Logger.INSTANCE.debug("e");
          Logger.INSTANCE.debug("f");
          Logger.INSTANCE.debug("g");
          Logger.INSTANCE.debug("h");
  
      }
  }
  </code></pre>
  
  <p>after test my console wrriten this message 
  11:14:53 DEBUG [Thread-1] LOGGER - a</p>
  
  <p>and my log file wrriten this messages</p>
  
  <pre><code>11:14:53 DEBUG [Thread-1] LOGGER - a
  11:14:53 DEBUG [Thread-1] LOGGER - b
  11:14:53 DEBUG [Thread-1] LOGGER - b
  11:14:53 DEBUG [Thread-1] LOGGER - c
  11:14:53 DEBUG [Thread-1] LOGGER - c
  11:14:53 DEBUG [Thread-1] LOGGER - d
  11:14:53 DEBUG [Thread-1] LOGGER - d
  11:14:53 DEBUG [Thread-1] LOGGER - e
  11:14:53 DEBUG [Thread-1] LOGGER - e
  11:14:53 DEBUG [Thread-1] LOGGER - f
  .....
  </code></pre>
  
  <p>i think first log is writen to console</p>
  
  <p>and others is writen to file</p>
  
  <p>what's this program's problem..</p>
  
  <p>thanks</p>