GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reduce silent log event loss during XmlConfigurator reconfiguration by N0tre3l · Pull Request #287 · apache/logging-log4net

Conversation

@N0tre3l

@N0tre3l N0tre3l commented Apr 8, 2026 •
edited by FreeAndNil
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
N0tre3l added 3 commits April 8, 2026 19:57
@N0tre3l
feat(Logger): add ReplaceAppenders for atomic appender swap
21d4a0b
Add method to atomically replace all appenders with a new collection.
@N0tre3l
Enable diagnostics by resetting Emfix(Hierarchy): reset EmittedNoAppe…
5034762
…nderWarning in ResetConfigurationittedNoAppenderWarning

Reset the warning flag to allow diagnostics during reconfiguration.
@N0tre3l
fix(XmlHierarchyConfigurator): collect appenders before swap to minim…
908daac
…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
FreeAndNil requested changes Apr 8, 2026
View reviewed changes

@FreeAndNil FreeAndNil left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread src/log4net/Repository/Hierarchy/Hierarchy.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/log4net/Repository/Hierarchy/Logger.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/log4net/Repository/Hierarchy/XmlHierarchyConfigurator.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@N0tre3l
Fix: address reviewer feedback and add unit tests
1443883
@N0tre3l

N0tre3l commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Hello @FreeAndNil,
I have addressed all the requested changes and added the unit tests. Ready for CI checks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@N0tre3l
Fix: resolve CS0118 and CA1062 properly
2132198
@N0tre3l
N0tre3l requested a review from FreeAndNil April 9, 2026 11:51
@N0tre3l
Fix: remove internal flag test to fix CS1061 build error
605908d
@FreeAndNil

FreeAndNil commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

@N0tre3l I will take a look at the failing SMTP test.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@N0tre3l
Fix: resolve flaky SmtpPickupDirAppenderTest.TestOutputContainsSentDa…
f55d2fc
…te in CI
FreeAndNil
FreeAndNil requested changes Apr 9, 2026
View reviewed changes

@FreeAndNil FreeAndNil left a comment

Copy link
Copy Markdown
Contributor

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.

nearly done ;-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/log4net/Repository/Hierarchy/Hierarchy.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/log4net.Tests/Hierarchy/LoggerTest.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/log4net/Repository/Hierarchy/Logger.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/log4net/Repository/Hierarchy/Logger.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@N0tre3l
Fix: address reviewer feedback - use EnsureNotNull, fix whitespace, a…
cc5d822
…dd atomicity test
@N0tre3l

N0tre3l commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@N0tre3l
Fix: add missing using System.Threading for atomicity test
db6f12a
@N0tre3l

N0tre3l commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the extra noise — I forgot to add using System.Threading; for the new atomicity test. Fixed now! 🙈

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@FreeAndNil 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
FreeAndNil
FreeAndNil requested changes Apr 9, 2026
View reviewed changes

@FreeAndNil FreeAndNil left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread src/log4net/Repository/Hierarchy/Logger.cs Outdated
_appenderLock.ReleaseWriterLock();
}
}
}

@FreeAndNil FreeAndNil Apr 9, 2026

Copy link
Copy Markdown
Contributor

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.

Suggested change
}
}

Sorry, one last nit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@FreeAndNil FreeAndNil added the bug label Apr 9, 2026
@FreeAndNil FreeAndNil added this to the 3.3.1 milestone Apr 9, 2026
@N0tre3l
Fix: remove extra indentation on closing brace
7664c7a
FreeAndNil added a commit that referenced this pull request Apr 9, 2026
@FreeAndNil
added release note for #287
69bb9f4
FreeAndNil
FreeAndNil approved these changes Apr 10, 2026
View reviewed changes

@FreeAndNil FreeAndNil left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@FreeAndNil
FreeAndNil merged commit 592d18d into apache:master Apr 10, 2026
3 checks passed

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Apr 20, 2026
Bump the runtime-libraries group with 3 updates CreativeCodersTeam/Core#104
Closed
Bump the other-dependencies group with 27 updates CreativeCodersTeam/Core#105
Closed
Bump log4net from 3.3.0 to 3.3.1 ParadoxGameConverters/PGCG.commonItems#819
Merged
Bump log4net from 3.3.0 to 3.3.1 AlexHedley/poker-recording#272
Merged
Bump log4net from 3.3.0 to 3.3.1 bbtsoftware/AzureDevOpsPolicyConfigurator#248
Merged
Bump log4net from 3.3.0 to 3.3.1 micutio/TermRTS#32
Merged
This was referenced Jun 21, 2026
Bump log4net and 3 others frasermolyneux/demo-manager#55
Closed
Bump log4net and 3 others frasermolyneux/demo-manager#58
Closed
Bump log4net from 2.0.8 to 3.3.2 strobes-test/MkartLogistics#50
Open
Bump log4net from 3.3.0 to 3.3.2 rogerbriggen/aspire_otel_test#79
Merged
Bump the all-updates group with 5 updates frasermolyneux/demo-manager#61
Closed
@dependabot dependabot Bot mentioned this pull request Jul 1, 2026
Bump log4net from 3.3.0 to 3.3.2 MjrTom/CastleCore#51
Open
This was referenced Jul 10, 2026
Bump the dependencies group with 10 updates guibranco/CrispyWaffle#962
Merged
Bump log4net from 3.3.0 to 3.3.2 Ed-Fi-Alliance-OSS/ODS-Admin-API#395
Closed
@dependabot dependabot Bot mentioned this pull request Jul 19, 2026
Bump log4net and 4 others frasermolyneux/demo-manager#63
Closed
@dependabot dependabot Bot mentioned this pull request Aug 5, 2026
DEV: Bump log4net from 3.3.0 to 3.3.2 origam/origam#4638
Merged
This was referenced Aug 14, 2026
deps: Bump the all-patch group with 5 updates OliverRetro/WavePlus#41
Merged
Bump the all-updates group with 5 updates frasermolyneux/demo-manager#66
Closed
@dependabot dependabot Bot mentioned this pull request Aug 23, 2026
Bump the all-updates group with 5 updates frasermolyneux/demo-manager#67
Merged
This was referenced Sep 2, 2026
Bump log4net from 3.3.0 to 3.4.0 Ed-Fi-Alliance-OSS/ODS-Admin-API#451
Merged
chore: Bump log4net from 2.0.17 to 3.4.0 mdallago/MDLSoft.NHibernate.AspNet#4
Merged
@N0tre3l N0tre3l mentioned this pull request Sep 13, 2026
No validation that deposit receiver is the actual user (msg.sender) intuition-box/Fee-Proxy-Template#1
Open
FreeAndNil added a commit that referenced this pull request Sep 19, 2026
@FreeAndNil
close the outgoing appenders before activating the new ones #321
92bd74b
- 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
File lock error when using FileAppender with XmlConfigurator.ConfigureAndWatch (v3.3.1) #321
Closed
close the outgoing appenders before activating the new ones #321 #322
Merged
FreeAndNil added a commit that referenced this pull request Sep 21, 2026
@FreeAndNil
close the outgoing appenders before activating the new ones #321
642bdd2
- 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
@FreeAndNil
close the outgoing appenders before activating the new ones #321 - #322
781b4a8
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
Bump the minor-and-patch group with 6 updates digst/OIOSAML.Net#91
Closed
Bump the minor-and-patch group with 1 update digst/OIOSAML.Net#99
Merged
Bump log4net from 2.0.8 to 3.5.0 devsecops-lab-luis/demo-ghas-multilenguaje#12
Closed
This was referenced Nov 11, 2026
Bump log4net from 3.2.0 to 3.5.0 marcmy/ProtonVPN-win-app#153
Closed
Dependency (dependabot/nuget): Bump log4net from 3.2.0 to 3.5.0 sg-scale/NETworkManager--2025.10.18.0#10
Open
Bump log4net from 3.3.0 to 3.5.0 chutch3/kenku#87
Merged
Bump log4net from 2.0.15 to 3.6.0 sg-scale/NETworkManager--2022.12.20.0#5
Open
Bump log4net from 2.0.8 to 3.6.0 devsecops-lab-luis/demo-ghas-multilenguaje#27
Open
Dependency (dependabot/nuget): Bump log4net from 3.3.0 to 3.6.0 Nevergoodstudy/NETworkManager-macOS#24
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@FreeAndNil FreeAndNil FreeAndNil approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bug

Projects

None yet

Milestone

3.3.1

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@N0tre3l @FreeAndNil
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.