title: Logback AsyncAppender is not working for FileAppender with custom Layout implementation
body: <p>Logback's <code>AsyncAppender</code> is not logging when we link it with <code>FileAppender</code> which uses custom layout implementation. I have used below FileAppender with custom implementation of <code>com.myorg.log.MaskingPatternLayout</code> under <code>LayoutWrappingEncoder</code>.</p>
  
  <p>Below is the snippet of <code>logback.xml</code> file:</p>
  
  <pre><code>//Not Working with AsycnAppender
  &lt;appender name="FILE_ASYNC_CUSTOM" class="ch.qos.logback.core.FileAppender"&gt;
      &lt;file&gt;log/async.log&lt;/file&gt;
      &lt;encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"&gt;
          &lt;layout class="com.myorg.log.MaskingPatternLayout"&gt;
              &lt;patternsProperty&gt;password,dateOfBirth&lt;/patternsProperty&gt;
              &lt;pattern&gt;%d %-4relative [%thread] %-5level %logger{35} - %msg%n&lt;/pattern&gt;
          &lt;/layout&gt;
      &lt;/encoder&gt;
  &lt;/appender&gt;
  &lt;appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender"&gt;
      &lt;appender-ref ref="FILE_ASYNC_CUSTOM" /&gt;
  &lt;/appender&gt;
  
  //Working with AsycnAppender
  &lt;appender name="FILE_ASYNC_NO_CUSTOM" class="ch.qos.logback.core.FileAppender"&gt;
      &lt;file&gt;log/async.log&lt;/file&gt;
      &lt;encoder&gt;
          &lt;pattern&gt;%d %-4relative [%thread] %-5level %logger{35} - %msg%n&lt;/pattern&gt;
      &lt;/encoder&gt;
  &lt;/appender&gt;
  &lt;appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender"&gt;
      &lt;appender-ref ref="FILE_ASYNC_NO_CUSTOM" /&gt;
  &lt;/appender&gt;
  </code></pre>
  
  <p>Below is the custom implementation of <code>PatternLayout</code>.</p>
  
  <pre><code>@Slf4j
  public class MaskingPatternLayout extends PatternLayout {
  
      private String patternsProperty;
      private Optional&lt;Pattern&gt; pattern;
  
      public String getPatternsProperty() {
          return patternsProperty;
      }
  
      public void setPatternsProperty(String patternsProperty) {
          this.patternsProperty = patternsProperty;
          if (this.patternsProperty != null) {
              this.pattern = Optional.of(Pattern.compile(getPatternToReplace(Arrays.asList(patternsProperty.split(",")))));
          } else {
              this.pattern = Optional.empty();
          }
      }
  
      @Override
      public String doLayout(ILoggingEvent event) {
          final StringBuilder message = new StringBuilder(super.doLayout(event));
          String maskedBody = message.toString();
          if (pattern.isPresent()) {
              Matcher matcher = pattern.get().matcher(message);
              while (matcher.find()) {
                  maskedBody = maskedBody.replaceAll(matcher.group(0)
                      , matcher.group(0)
                          .replace(matcher.group(4)
                              , encode(matcher.group(4))));
              }
          }
          try {
              Thread.sleep(100);
          } catch (InterruptedException e) {
              log.error("Error on thread sleep: {}", e.getMessage());
          }
  
          return maskedBody;
      }
  
      private String getPatternToReplace(List&lt;String&gt; listToMask) {
          final StringBuilder sb = new StringBuilder();
          Optional.ofNullable(listToMask)
              .filter(test -&gt; !test.isEmpty())
              .ifPresent((List&lt;String&gt; list) -&gt; {
                  sb.append(list.stream().map(String::trim).collect(Collectors.joining("|", "\"(", ")\"")));
                  sb.append("(\\s)*:(\\s)*\"(.*?)\"");
              });
          return Optional.of(sb).map(StringBuilder::toString).filter(StringUtils::isNotEmpty).get();
      }
  
      private String encode(final CharSequence cs) {
          try {
              final byte[] csInUtf8 = Utf8.encode(cs);
              final String csString = Utf8.decode(csInUtf8);
              final String secret = "testing";
  
              final Integer iteration = 10;
  
              final Integer keyLength = 512;
  
              final byte[] result = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512")
                  .generateSecret(new PBEKeySpec(csString.toCharArray(), secret.getBytes(StandardCharsets.UTF_8), iteration, keyLength))
                  .getEncoded();
  
              return Base64.getEncoder().encodeToString(result);
          } catch (final NoSuchAlgorithmException | InvalidKeySpecException ex) {
              log.error("error: {}, value: {}", ex.getMessage(), cs, ex);
              throw new RuntimeException(ex);
          }
      }
  
  }
  </code></pre>
  
  <p>Expected is to log the events in log file asynchronously but no logs are getting generated in "log/async.log". But at the same time when I try to use <code>FileAppender</code> without custom layout then it works fine.</p>