Fix replication_log with external log4j.configuration

When using an external log4j configuration using the JVM container
option -Dlog4j.configuration=file:///... the replication log appender
wasn’t configured at all.

This was mainly due to the fact that all appenders were closed and 
removed before invoking the SystemLog.createAsyncAppender() that was
then unable to find any appender to attach.

Flipping the operations and using the single removeAppender instead
of the removeAllAppenders (the name is a lie: it does not only remove
but also *CLOSE* all the appenders, making them unusable) everything
is OK with an external configuration.

Issue: 3230
Change-Id: I4d9b153d49731a0a7d5c5df863c69dd2165cc883
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java
index 1079981..50f1b8b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java
@@ -19,6 +19,7 @@
 import com.google.gerrit.server.util.SystemLog;
 import com.google.inject.Inject;
 
+import org.apache.log4j.AsyncAppender;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
@@ -41,10 +42,12 @@
     if (!started) {
       Logger replicationLogger =
           LogManager.getLogger(ReplicationQueue.REPLICATION_LOG_NAME);
-      replicationLogger.removeAllAppenders();
-      replicationLogger.addAppender(systemLog.createAsyncAppender(
-          replicationLogger.getName(), new PatternLayout("[%d] [%X{"
-              + PushOne.ID_MDC_KEY + "}] %m%n")));
+      String loggerName = replicationLogger.getName();
+      AsyncAppender asyncAppender = systemLog.createAsyncAppender(
+          loggerName, new PatternLayout("[%d] [%X{"
+              + PushOne.ID_MDC_KEY + "}] %m%n"));
+      replicationLogger.removeAppender(loggerName);
+      replicationLogger.addAppender(asyncAppender);
       replicationLogger.setAdditivity(false);
       started = true;
     }