Skip to content

Optionally preserve logging scopes in buffered records #7781

Description

@Dreamescaper

Problem

Log buffering currently does not preserve ILogger.BeginScope data. The log buffering documentation lists scopes as unsupported, so when buffered records are flushed they are no longer associated with the scope that was active when each record was written. This loses useful request, message, and operation context precisely when buffered logs are emitted for investigation.

Why capture at enqueue time

During the original implementation, reviewers noted that the scope provider reports the scope active at flush time, which may differ from the scope active when a log was written. Looking up scopes only during flush could therefore associate a buffered record with the wrong scope. See the discussion on PR #5635.

Proposal

Consider adding opt-in scope capture to the built-in buffering implementation. Scope values should be captured when each log record is buffered and associated with that record when it is emitted, even if the original scope has already been disposed. Keep this optional so applications can avoid the extra memory and processing cost when they do not need scopes.

This would apply to global and per-request buffering, subject to the available scope context in each pipeline.

Related: #6113 documented that scopes are currently unsupported.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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