elastic / ecs-dotnet

https://www.elastic.co/guide/en/ecs-logging/dotnet/current/setup.html
Apache License 2.0
108 stars 54 forks source link

log4net layout: log latest scope value #367

Closed andreycha closed 3 months ago

andreycha commented 3 months ago

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

Mpdreamz commented 3 months ago

run docs-build

Mpdreamz commented 3 months ago

Thank you for another excellent PR, @andreycha!

andreycha commented 3 months ago

@Mpdreamz thanks for checking it quickly!