Skip to content

[Feature]: Host-wide log capture across all categories via Compono.Logging #164

Closed

Description

@ncipollina

Child of #161 (item 1). Split out during feature intake so it can be tracked, researched and decided on its own. API names in this issue are illustrative only. They are not approved designs.

Motivation

Consumer scenario (#161, Compono 1.3.2 migration): a Generic Host test asserts that nothing was logged at Error or above in any category, including framework and library categories the test never composes (a scheduler, the hosting layer). Those loggers are created by the host's ILoggerFactory, not by Compono.

What Compono does today (validated against main):

  • Compono.Logging composes ILogger/ILogger<T> as CapturingLogger/CapturingLogger<T> through a stage-6 provider (UseLogging()).
  • Each captured logger owns its own internal LogEntryCollector. There is no collector shared across loggers, even between two composed loggers.
  • CapturedLogEntry has no category field. That doesn't matter while each logger is per-category, but it does once entries from many categories go into one place.
  • There is no ILoggerProvider, ILoggerFactory or ILoggingBuilder integration. ADR-0055 lists "ILoggerFactory composition" as a v1 non-goal and defers it "until real evidence demands it". This issue is that evidence.

Workaround in use: keep Microsoft.Extensions.Diagnostics.Testing (AddFakeLogging() + FakeLogCollector) for this one guard. The suite then has two log-capture models with two verification vocabularies.

Classification: a missing capability, and an unsupported integration (host logging pipeline). Not a bug: no Compono doc or ADR claims host-wide capture.

Proposed solution

Consumer requirement (outcome, not API): a host-based test can capture entries from every logger the host creates and verify them with the same Compono-native model Compono.Logging already uses (CapturedLogEntry, Verify() / CallVerifier counting), including a cross-category check such as "no entry at or above Error".

Acceptance criteria

  • Entries from host-created loggers of any category are captured, including categories the test never composes.
  • Each captured entry exposes its category, plus the existing level, event id, message, exception, structured properties, message template and scopes.
  • Captured entries can be verified with the existing Verify() vocabulary (or a deliberate, documented extension of it), including a level-threshold check across all categories.
  • Existing composed ILogger<T> capture behaves exactly as today. No breaking change to CapturingLogger, CapturedLogEntry or UseLogging().
  • The relationship between host-captured entries and composed-logger entries (shared or separate) is decided and documented.
  • No new package dependency beyond what Compono.Logging already brings, unless the ADR justifies one.
  • Native AOT and trimming compatibility kept (IsAotCompatible stays true, no reflection).

Relevant packages: Compono.Logging (likely home). Core Compono only if a shared-collector concept needs a core seam (not expected). Intake finding: ILoggerProvider and ILoggingBuilder both live in Microsoft.Extensions.Logging.Abstractions, which Compono.Logging already references, and that package already depends on Microsoft.Extensions.DependencyInjection.Abstractions. A provider-based integration therefore looks possible without a new package or a new dependency. A separate integration package does not currently look justified.

Research questions (to settle before an ADR)

  1. Provider or factory? Should Compono add an ILoggerProvider to the host's existing logging pipeline (the host keeps its own ILoggerFactory), or does any scenario need a composed ILoggerFactory? The working assumption is that Compono should not replace the host's factory.
  2. Can LogEntryCollector become shareable across loggers, or does sharing need a new public collector concept? What is its public surface and thread-safety contract?
  3. Should composed loggers and host-created loggers write to the same collector? How would a test get both into one collector (Share<T>(), a profile, an explicit instance)?
  4. Scope semantics: provider-level ISupportExternalScope / SetScopeProvider (the host's scope provider) versus today's per-logger LoggerExternalScopeProvider. Do snapshots stay outermost-to-innermost and stay correct across await?
  5. Filtering: how do host LoggerFilterOptions / category filters interact with LoggingOptions.MinimumLevel? Which one decides what gets captured?
  6. Lifetime: the host disposes its providers. Compono is non-owning (ADR-0022 Amendment 4, RESEARCH-0015). Who owns the provider and collector, and is any read still valid after the host is disposed?
  7. Is adding Category to CapturedLogEntry source/binary compatible? It is a readonly record struct with an internal constructor. What category value do directly constructed CapturingLogger / CapturingLogger<T> instances report?
  8. How should this be verified in a real Generic Host test? Is a dogfood consumer available?

Compatibility / AOT / performance: additive only. No reflection. Snapshot reads already allocate. Check the cost of contention on a lock shared by many categories under heavy host logging.

Explicit non-goals

Relationship / dependencies: child of #161 (item 1). No hard dependency on the other #161 items. Soft relationship with #165 (metrics): both currently keep Microsoft.Extensions.Diagnostics.Testing in the suite, so the consumer can drop that package only once both are addressed.

Suggested process: capability-admission check (Gate B already met by real migration evidence), then a light-to-medium design dive and an ADR (likely an amendment or extension of ADR-0055's ILoggerFactory non-goal). A standalone research doc is probably not needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    💡 idea

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions