Repository navigation
Description
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.LoggingcomposesILogger/ILogger<T>asCapturingLogger/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. CapturedLogEntryhas 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,ILoggerFactoryorILoggingBuilderintegration. ADR-0055 lists "ILoggerFactorycomposition" 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 toCapturingLogger,CapturedLogEntryorUseLogging(). - The relationship between host-captured entries and composed-logger entries (shared or separate) is decided and documented.
- No new package dependency beyond what
Compono.Loggingalready brings, unless the ADR justifies one. - Native AOT and trimming compatibility kept (
IsAotCompatiblestays 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)
- Provider or factory? Should Compono add an
ILoggerProviderto the host's existing logging pipeline (the host keeps its ownILoggerFactory), or does any scenario need a composedILoggerFactory? The working assumption is that Compono should not replace the host's factory. - Can
LogEntryCollectorbecome shareable across loggers, or does sharing need a new public collector concept? What is its public surface and thread-safety contract? - 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)? - Scope semantics: provider-level
ISupportExternalScope/SetScopeProvider(the host's scope provider) versus today's per-loggerLoggerExternalScopeProvider. Do snapshots stay outermost-to-innermost and stay correct acrossawait? - Filtering: how do host
LoggerFilterOptions/ category filters interact withLoggingOptions.MinimumLevel? Which one decides what gets captured? - 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?
- Is adding
CategorytoCapturedLogEntrysource/binary compatible? It is areadonly record structwith an internal constructor. What category value do directly constructedCapturingLogger/CapturingLogger<T>instances report? - 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
- Replacing or wrapping the host's
ILoggerFactory. - Serilog/NLog or other provider-specific behavior. Test-runner output routing.
- Depending on
Microsoft.Extensions.Diagnostics.Testing. - Runtime log-level toggling (
FakeLogger.ControlLevel-style), unless research shows the threshold model can't express the scenario. - Metrics ([Feature]: Metrics testing: observe IMeterFactory-created instruments in composed tests #165).
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.
Activity
docs: land accepted #164 planning artifacts (ADR-0071, ADR-0055 Amd 6…
chore(dotnet11): migrate to .NET 11 GA (B1, PLAN-0072) (#176)
docs(plan): record #164 validation and PR #177 (PLAN-0072)
fix(logging): honor capture re-registration and enable Compono alias …
feat(compono-logging): host-wide log capture via LogCollector (#164) (#…