Skip to content

Attach hierarchical scope to log events #50

Closed
@nblumhardt

Description

@nblumhardt

Currently, BeginScope() will cause any properties on the state object to be attached to resulting events:

https://github.com/serilog/serilog-extensions-logging/blob/dev/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs#L53

and:

https://github.com/serilog/serilog-extensions-logging/blob/dev/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs#L61

However, it's also possible to use string "names" with scopes, and in that case some form of scope path should be attached to the event. For example:

using (log.BeginScope("A"))
{
    using (log.BeginScope("B")
    {
        log.LogInformation("Hello");
    }
}

produces a scope like "A -> B" in the default console logger output.

Serilog might attach these as a Sequence property, e.g. (in JSON rendering) "Scope": ["A", "B"].

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions