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

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

Reply via email to