Skip to content

Enable to enrich logs from what is currently in IDiagnosticContextΒ #384

@tsimbalar

Description

@tsimbalar

Is your feature request related to a problem? Please describe.
I am happy using IDiagnosticContext to "add stuff" that will end up being available in the final Serilog/end of request log event ... but I'm a bit annoyed that all those properties I have attached are not available for other instances of log events generated within the same HTTP Request.

I guess what I'm looking for is a LogContext.Push where I wouldn't have to .Dispose(), and would last until the end of the current HTTP Request.

Describe the solution you'd like
I understand this is not a behavior we'd want to enable by default (this would be a breaking change)... but maybe we'd like to explicit be able to Enrich.FromDiagnosticContext(), i.e. whenever I am emitting a LogEvent, look if there is anything inside the current DiagnosticContext of the current HttpRequest, and attach those as well.

Describe alternatives you've considered
Maybe I could somehow add another place that is "within Http Request" where I'd store things for the scope of the request's duration, and have an Enricher that would read from it πŸ€”

Comments
At this point I'm pretty sure it's technically doable (within this library, or separately with custom code) ... but I'm also trying to figure out where it's actually a good idea in the first place, or there are good reasons NOT to do it πŸ˜…

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