You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "FreeAndNil (via GitHub)" <gi...@apache.org> on 2026/04/09 21:32:49 UTC

Re: [PR] Reduce silent log event loss during XmlConfigurator reconfiguration (logging-log4net)

FreeAndNil commented on code in PR #287:
URL: https://github.com/apache/logging-log4net/pull/287#discussion_r3060776986


##########
src/log4net/Repository/Hierarchy/Logger.cs:
##########
@@ -594,4 +595,36 @@ protected virtual void ForcedLog(LoggingEvent logEvent)
 
     CallAppenders(logEvent);
   }
-}
\ No newline at end of file
+
+  /// <summary>
+  /// Atomically replaces all appenders with the provided collection.
+  /// </summary>
+  /// <param name="appenders">The new set of appenders to attach.</param>
+  /// <remarks>
+  /// <para>
+  /// This method removes the existing appenders and attaches all new
+  /// appenders inside a single writer lock, minimizing the window
+  /// during which the logger has no appenders. This reduces silent log
+  /// event loss during reconfiguration.
+  /// </para>
+  /// </remarks>
+  public virtual void ReplaceAppenders(IEnumerable<IAppender> appenders)
+  {
+    _appenderLock.AcquireWriterLock();
+    try
+    {
+      _appenderAttachedImpl?.RemoveAllAppenders();
+      _appenderAttachedImpl = null;
+
+      foreach (IAppender appender in appenders.EnsureNotNull())
+      {
+        _appenderAttachedImpl ??= new();
+        _appenderAttachedImpl.AddAppender(appender);
+      }
+    }
+    finally
+    {
+      _appenderLock.ReleaseWriterLock();
+    }
+  }
+                            }

Review Comment:
   ```suggestion
   }
   ```
   Sorry, one last nit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org