GeezerVison is showing github.com — Reduce silent log event loss during XmlConfigurator reconfiguration by N0tre3l · Pull Request #287 · apache/logging-log4net
Conversation
N0tre3l
commented
Apr 8, 2026
•
edited by FreeAndNil
Loading
Uh oh!
There was an error while loading. Please reload this page.
Problem
During reconfiguration (XmlConfigurator.Configure in Merge mode),
XmlHierarchyConfigurator.ParseChildrenOfLoggerElement called
RemoveAllAppenders() first, then parsed the XML and re-added appenders
one by one. Any log event fired during the XML parse window (10-50 ms in
typical applications) was silently dropped because CallAppenders found
_appenderAttachedImpl == null.
Measured impact in a reproducible test: 95.9 % of events lost during a
50 ms simulated reconfiguration window.
Changes
Logger.cs - new ReplaceAppenders(IEnumerable<IAppender>) method
Removes the old appender collection and adds all new appenders inside a
single writer lock, so the logger is never in a zero-appender state for
more than a few microseconds (the lock acquisition time).
XmlHierarchyConfigurator.cs - collect-then-swap in ParseChildrenOfLoggerElement
All new appenders are resolved from XML into a List<IAppender> before
the live logger is touched. Then Logger.ReplaceAppenders() is called once
to perform the atomic swap, rather than the previous remove-then-add-one-by-one
pattern.
XmlHierarchyConfigurator.cs - reset EmittedNoAppenderWarning in Configure
The "no appender" warning is intentionally designed to fire once per
application lifetime. However, with the appender swap window now reduced to
microseconds, an unlucky event hitting that window would permanently suppress
the diagnostic for the rest of the application lifetime. Resetting the flag at
the start of each configuration pass restores the intended behavior: one
warning per reconfiguration cycle if events are lost.
The reset is placed in Configure() rather than Hierarchy.ResetConfiguration()
because ResetConfiguration() is only called in Overwrite mode, which would
leave Merge mode - the default and the affected mode - without the reset.
Testing
Manually verified that:
XmlConfigurator.Configure still attaches the correct appenders after
reconfiguration in both Merge and Overwrite modes.
- The zero-appender window is no longer observable under concurrent logging load.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add method to atomically replace all appenders with a new collection.
…nderWarning in ResetConfigurationittedNoAppenderWarning
Reset the warning flag to allow diagnostics during reconfiguration.
…ize null window
Previously, ParseChildrenOfLoggerElement called RemoveAllAppenders()
before adding new ones one-by-one, creating a window (equal to the full
XML parse duration, typically 10-50 ms) during which the logger had no
appenders and log events were silently dropped.
This change resolves the race by:
1. Collecting all incoming appenders into a local List<IAppender> first.
2. Calling Logger.ReplaceAppenders() to perform the swap in a single
writer lock, reducing the zero-appender window to microseconds.
FreeAndNil
left a comment
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@N0tre3l thanks for your contribution.
Could you please add some unit tests and fix the compiler errors?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Hello @FreeAndNil,
I have addressed all the requested changes and added the unit tests. Ready for CI checks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@N0tre3l I will take a look at the failing SMTP test.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
All changes addressed! Reverted to EnsureNotNull() on the foreach (good call — much cleaner), removed the trailing whitespace, and added TestReplaceAppendersIsAtomic which spins a reader thread watching for zero-appender windows during 1,000 rapid replacements. Should cover the atomicity concern nicely. Thanks for the patience!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sorry for the extra noise — I forgot to add using System.Threading; for the new atomicity test. Fixed now! 🙈
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
FreeAndNil
changed the title
Fix/reduce event loss on reconfigurationreduce silent log event loss during XmlConfigurator reconfiguration
Reduce silent log event loss during XmlConfigurator reconfiguration
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, one last nit. After this we are ready to merge.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
_appenderLock.ReleaseWriterLock();
|
|
|
}
|
|
|
}
|
|
|
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Apr 20, 2026
This was referenced Jun 21, 2026
This was referenced Jul 10, 2026
This was referenced Aug 14, 2026
This was referenced Sep 2, 2026
FreeAndNil
added a commit
that referenced
this pull request
Sep 19, 2026
- XmlHierarchyConfigurator activated a new appender while the outgoing
one still held its file, so ConfigureAndWatch failed with "Unable to
acquire lock on file"
- regression from 592d18d (#287)
- ParseAppender collects into _pendingActivations, which Configure
drains once every logger has swapped
- the symptom is Windows only: .NET on Linux does not enforce FileShare
within a process, so the test asserts the open/close order instead
This was referenced Sep 19, 2026
FreeAndNil
added a commit
that referenced
this pull request
Sep 21, 2026
- XmlHierarchyConfigurator activated a new appender while the outgoing
one still held its file, so ConfigureAndWatch failed with "Unable to
acquire lock on file"
- regression from 592d18d (#287)
- ParseAppender collects into _pendingActivations, which Configure
drains once every logger has swapped
- the symptom is Windows only: .NET on Linux does not enforce FileShare
within a process, so the test asserts the open/close order instead
FreeAndNil
added a commit
that referenced
this pull request
Sep 22, 2026
Fixes #321
- since #287 (3.3.1) the new appenders were activated, and so opened their file, before the old ones were closed
- `ParseAppender` now collects into `_pendingActivations`, drained once every logger has swapped; the atomic swap from #287 stays
- verified on Windows, `net462`: one `Unable to acquire lock` per run before, none after
- Linux cannot show the symptom, so the test asserts the open/close order instead
This was referenced Oct 26, 2026
This was referenced Nov 11, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|