GeezerVison is showing github.com — Add Peek() method to ThreadContextStack and LogicalThreadContextStack. by andreycha · Pull Request #101 · apache/logging-log4net
Conversation
andreycha
commented
Apr 26, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Change
Add Peek() method to ThreadContextStack and LogicalThreadContextStack to be able to get the most recent value from the context without removing it.
Motivation
In the scope of ElasticCommonSchema .NET integration for log4net log entry properties are being read and written to ECS format. In case of context stacks current implementation takes string representation of the stack. It works fine when stack (i.e., property) has a single value, but there are also cases when stack contains multiple values (same or different ones). With the proposed changes it will be able to take the most recent value, in the context of which the current log entry is being written.
Consider following scenario:
using (LogicalThreadContext.Stacks["Id"].Push("123"))
{
log.Info("Log 1"); // currently has "123" in the log metadata
using (LogicalThreadContext.Stacks["Id"].Push("456"))
{
log.Info("Log 2"); // currently has "123 456" in the log metadata; should have "456" instead
using (LogicalThreadContext.Stacks["Id"].Push("789"))
{
log.Info("Log 3"); // currently has "123 456 789" in the log metadata; should have "789" instead
}
}
}
Alternative solutions considered
An alternative approach might be to just pop the most recent value and then push it again onto the stack. Problem here is that it creates a new scope which will not be closed as no one will call Dispose() on the returned result from Push().
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hi @fluffynuts , could you please check this PR? Thanks!
|
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.
LGTM
I can't make any promises about when this gets out live - I haven't had a lot of time to put into this in a while ): I'm currently formulating a plan to do beta / prerelease packages with less release friction so that perhaps at least things can get out quicker, but I have to speak with more venerable Apache people on what's process would be acceptable.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
andreycha reacted with rocket emoji
|
Thanks! Is there a way to somehow get notified when a new release comes out?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@andreycha I guess you could sub to apache logging email lists; but I really want to figure out a way to do beta releases, and I doubt they'd go through that, so 🤷 I haven't figured this out yet ): I have this tension between "actual releases are a major mission with a lot of dead time whilst I wait for a bunch of Java people to vote on a dotnet thing that they have no context about" and "I just want to release fixes" )':
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yeah, I can relate. Anyway, looking forward to the new release!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 19, 2025
This was referenced Nov 11, 2025
This was referenced Jan 7, 2026
This was referenced Jan 27, 2026
This was referenced Feb 3, 2026
This was referenced Aug 23, 2026
This was referenced Aug 31, 2026
This was referenced Sep 19, 2026
This was referenced Oct 8, 2026
This was referenced Oct 21, 2026
This was referenced Oct 29, 2026
This was referenced Nov 6, 2026
This was referenced Nov 13, 2026
This was referenced Nov 24, 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.
|