diff --git a/src/changelog/3.5.1/340-appender-name-not-unique.xml b/src/changelog/3.5.1/340-appender-name-not-unique.xml new file mode 100644 index 00000000..4d7b7bd8 --- /dev/null +++ b/src/changelog/3.5.1/340-appender-name-not-unique.xml @@ -0,0 +1,10 @@ + + + + Stop documenting `IAppender.Name` as unique. Uniqueness is not + enforced, and `GetAppender(string)` and `RemoveAppender(string)` now say they act on the first + attached appender with that name (reported by @hidingmyname, fixed by @FreeAndNil) + diff --git a/src/log4net/Appender/AppenderSkeleton.cs b/src/log4net/Appender/AppenderSkeleton.cs index fb0987b1..951f8f7a 100644 --- a/src/log4net/Appender/AppenderSkeleton.cs +++ b/src/log4net/Appender/AppenderSkeleton.cs @@ -179,7 +179,7 @@ public virtual void ActivateOptions() } /// - /// Gets or sets the name that uniquely identifies this appender. + /// Gets or sets the name of this appender. /// public string Name { get; set; } = string.Empty; diff --git a/src/log4net/Appender/BufferingForwardingAppender.cs b/src/log4net/Appender/BufferingForwardingAppender.cs index 47ca516b..d322f013 100644 --- a/src/log4net/Appender/BufferingForwardingAppender.cs +++ b/src/log4net/Appender/BufferingForwardingAppender.cs @@ -133,13 +133,7 @@ public virtual AppenderCollection Appenders } } - /// - /// Looks for the appender with the specified name. - /// - /// The name of the appender to lookup. - /// - /// The appender with the specified name, or . - /// + /// public virtual IAppender? GetAppender(string? name) { lock (LockObj) @@ -195,16 +189,7 @@ public virtual void RemoveAllAppenders() return null; } - /// - /// Removes the appender with the specified name from the list of appenders. - /// - /// The name of the appender to remove. - /// The appender removed from the list - /// - /// The appender removed is not closed. - /// If you are discarding the appender you must call - /// on the appender removed. - /// + /// public virtual IAppender? RemoveAppender(string? name) { lock (LockObj) diff --git a/src/log4net/Appender/ForwardingAppender.cs b/src/log4net/Appender/ForwardingAppender.cs index ed0f485f..d1a1c3e9 100644 --- a/src/log4net/Appender/ForwardingAppender.cs +++ b/src/log4net/Appender/ForwardingAppender.cs @@ -123,18 +123,7 @@ public virtual AppenderCollection Appenders } } - /// - /// Looks for the appender with the specified name. - /// - /// The name of the appender to lookup. - /// - /// The appender with the specified name, or . - /// - /// - /// - /// Get the named appender attached to this appender. - /// - /// + /// public virtual IAppender? GetAppender(string? name) { lock (LockObj) @@ -190,16 +179,7 @@ public virtual void RemoveAllAppenders() return null; } - /// - /// Removes the appender with the specified name from the list of appenders. - /// - /// The name of the appender to remove. - /// The appender removed from the list - /// - /// The appender removed is not closed. - /// If you are discarding the appender you must call - /// on the appender removed. - /// + /// public virtual IAppender? RemoveAppender(string? name) { lock (LockObj) diff --git a/src/log4net/Appender/IAppender.cs b/src/log4net/Appender/IAppender.cs index a3a75f86..93f36a66 100644 --- a/src/log4net/Appender/IAppender.cs +++ b/src/log4net/Appender/IAppender.cs @@ -69,7 +69,7 @@ public interface IAppender /// /// The name of the appender. /// - /// The name uniquely identifies the appender. + /// Used to look the appender up by name. Uniqueness is not enforced, and a lookup returns the first match. /// string Name { get; set; } } diff --git a/src/log4net/Core/IAppenderAttachable.cs b/src/log4net/Core/IAppenderAttachable.cs index acdf866f..d4e5b1e7 100644 --- a/src/log4net/Core/IAppenderAttachable.cs +++ b/src/log4net/Core/IAppenderAttachable.cs @@ -74,6 +74,7 @@ public interface IAppenderAttachable /// Returns an attached appender with the specified. /// If no appender with the specified name is found will be /// returned. + /// If several attached appenders share the name, the first one attached is returned. /// /// IAppender? GetAppender(string? name); @@ -109,6 +110,7 @@ public interface IAppenderAttachable /// The appender removed from the list /// /// + /// If several attached appenders share the name, only the first one attached is removed. /// The appender removed is not closed. /// If you are discarding the appender you must call /// on the appender removed. diff --git a/src/log4net/Repository/Hierarchy/Logger.cs b/src/log4net/Repository/Hierarchy/Logger.cs index 016dc2c8..752c1a5f 100644 --- a/src/log4net/Repository/Hierarchy/Logger.cs +++ b/src/log4net/Repository/Hierarchy/Logger.cs @@ -218,11 +218,7 @@ public virtual AppenderCollection Appenders } } - /// - /// Look for the appender named as - /// - /// The name of the appender to lookup - /// The appender with the name specified, or . + /// public virtual IAppender? GetAppender(string? name) { _appenderLock.AcquireReaderLock(); @@ -295,18 +291,7 @@ public virtual void RemoveAllAppenders() return null; } - /// - /// Remove the appender passed as parameter form the list of appenders. - /// - /// The name of the appender to remove - /// The appender removed from the list - /// - /// - /// The appender removed is not closed. - /// If you are discarding the appender you must call - /// on the appender removed. - /// - /// + /// public virtual IAppender? RemoveAppender(string? name) { _appenderLock.AcquireWriterLock(); diff --git a/src/log4net/Util/AppenderAttachedImpl.cs b/src/log4net/Util/AppenderAttachedImpl.cs index e8c71953..99f4aa92 100644 --- a/src/log4net/Util/AppenderAttachedImpl.cs +++ b/src/log4net/Util/AppenderAttachedImpl.cs @@ -206,19 +206,7 @@ public AppenderCollection Appenders } } - /// - /// Gets an attached appender with the specified name. - /// - /// The name of the appender to get. - /// - /// The appender with the name specified, or if no appender with the - /// specified name is found. - /// - /// - /// - /// Lookup an attached appender by name. - /// - /// + /// public IAppender? GetAppender(string? name) { if (_appenderList is not null && name is not null) @@ -288,18 +276,7 @@ public void RemoveAllAppenders() return appender; } - /// - /// Removes the appender with the specified name from the list of appenders. - /// - /// The name of the appender to remove. - /// The appender removed from the list - /// - /// - /// The appender removed is not closed. - /// If you are discarding the appender you must call - /// on the appender removed. - /// - /// + /// public IAppender? RemoveAppender(string name) => RemoveAppender(GetAppender(name)); ///