FreeAndNil commented on code in PR #287:
URL: https://github.com/apache/logging-log4net/pull/287#discussion_r3060107025
##########
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:
```suggestion
foreach (IAppender appender in appenders.EnsureNotNull())
```
Maybe this could solve your warning.
##########
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)
Review Comment:
appenders.EnsureNotNull();
I saw that you already used this. Why did you have to change it?
##########
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:
The you could skip the null check at the start.
##########
src/log4net/Repository/Hierarchy/Hierarchy.cs:
##########
@@ -283,7 +283,7 @@ public override void ResetConfiguration()
{
Root.Level = LevelMap.LookupWithDefault(Level.Debug);
Threshold = LevelMap.LookupWithDefault(Level.All);
-
+
Review Comment:
```suggestion
```
##########
src/log4net.Tests/Hierarchy/LoggerTest.cs:
##########
@@ -342,4 +342,22 @@ public void TestHierarchy1()
Logger a1 = (Logger)h.GetLogger("a");
Assert.That(a1, Is.SameAs(a0));
}
+
+ /// <summary>
+ /// Tests the ReplaceAppenders method to ensure it replaces existing
appenders
+ /// </summary>
+ [Test]
+ public void TestReplaceAppenders()
Review Comment:
Could you add an additional test which tests the atomicity of
ReplaceAppenders?
--
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]