Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log4net layout: log latest scope value #367

Merged
merged 4 commits into from
Apr 4, 2024
Merged

log4net layout: log latest scope value #367

merged 4 commits into from
Apr 4, 2024

Conversation

andreycha
Copy link
Contributor

@andreycha andreycha commented Apr 2, 2024

Motivation
If a property is added to the log scope multiple times, currently all its values are logged in metadata/labels. This is how log4net also behaves but in most of the cases it is undesired behavior. Only latest property value should be included (e.g., Serilog behaves the same way).

Example:

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
        }
    }
}

Breaking change: yes (comparing to how log4net behaves by default)

Changes

  • Log latest property value
  • Update to the latest log4net version (2.0.17), this is required to use Peek() method
  • Update test names
  • Use file-scoped namespaces
  • Update readme to reflect the latest version of generated events

@Mpdreamz
Copy link
Member

Mpdreamz commented Apr 4, 2024

run docs-build

Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mpdreamz Mpdreamz merged commit bd57c3b into elastic:main Apr 4, 2024
5 checks passed
@Mpdreamz
Copy link
Member

Mpdreamz commented Apr 4, 2024

Thank you for another excellent PR, @andreycha!

@andreycha
Copy link
Contributor Author

@Mpdreamz thanks for checking it quickly!

@andreycha andreycha deleted the feat/log4net-log-latest-scope-value branch April 4, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants