Skip to content

Allow separate contexts for different loggers #2

@augustoproiete

Description

@augustoproiete

Based on comment from @cassandra-d on StackOverflow:

Good answer and good work with nuget. A little bit unfortunate that that enricher works only globally and you can't set properties per logger instance to use it for distributed logging.


Given that enrichers are not sink-specific, I'm thinking that we would need to introduce something like "named contexts", and instruct the user to use sub-loggers to configure the enricher separately. It would look similar to the below (pseudo-code):

var consoleContext = GlobalLogContext.Create("Console");
var fileContext = GlobalLogContext.Create("File");

Log.Logger = new LoggerConfiguration()
    .WriteTo.Logger(lc => lc
        .WriteTo.Console()
        .Enrich.FromGlobalContext(consoleContext)
    )
    .WriteTo.Logger(lc => lc
        .WriteTo.File("log.txt")
        .Enrich.FromGlobalContext(fileContext)
    )
    .CreateLogger();

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions