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


##########
src/log4net/Repository/Hierarchy/Logger.cs:
##########
@@ -594,4 +595,41 @@ 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)
+  {
+    if (appenders == null)
+    {
+      throw new ArgumentNullException(nameof(appenders));
+    }
+
+    _appenderLock.AcquireWriterLock();
+    try
+    {
+      _appenderAttachedImpl?.RemoveAllAppenders();
+      _appenderAttachedImpl = null;
+
+      foreach (IAppender appender in appenders)

Review Comment:
   Then you could skip the null check at the start.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to