Skip to content

[Foundation] FT-6: Make logging thread-safe and per-run scoped (prereq for parallel execution) #311

Open

Description

@ChrisonSimtian

Summary

Make logging thread-safe and per-run scoped, so concurrent target execution (FT-8) is safe. Prerequisite for parallelism.

Findings (file:line)

  • Logging.cs:214 — InMemorySink.Instance with an unlocked List<LogEvent> (_logEvents); concurrent emits race.
  • Logging.cs:239-243 — target-context enricher uses a static s_property (SetAndRestore), not safe under concurrent targets.
  • Logging.cs:20 — global LevelSwitch; per-run level should live on the context.

Scope

  • Lock or use a concurrent collection for InMemorySink.
  • Replace the enricher's static s_property with AsyncLocal so per-target context is correct under concurrency.
  • Per-run level switch held on BuildContext.Logging.

Acceptance criteria

  • Concurrent emits don't race (stress test).
  • Per-target log context is correct under parallel execution.

Notes

  • Non-breaking.
  • Depends on: FT-2. Prerequisite for: FT-8.
  • Size: M.

Activity

  1. changed the title [-]FT-6: Make logging thread-safe and per-run scoped (prereq for parallel execution)[/-] [+][Foundation] FT-6: Make logging thread-safe and per-run scoped (prereq for parallel execution)[/+] on Jun 16, 2026
  2. ChrisonSimtian commented on Nov 18, 2026

    @ChrisonSimtian
    CollaboratorAuthor

    FT-6 is split. #453 moves the in-memory sink onto BuildContext (per run, no shared sink). Still open here:

    • Lock the sink's List<LogEvent> or use a concurrent collection, plus a stress test for concurrent emits.
    • Replace the enricher's static s_property with AsyncLocal.
    • Hold the level switch on the run's context.

    Also found in review: Log.Logger is process-wide, so two runs at once can send events to each other's sink. Decide whether this belongs in this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrelease/StableTargets the current/stable release

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions