Skip to content

Static ApplicationLogging.LoggerFactory is shared across Brighter instances in a process #4184

Description

@thomhurst

Problem

Brighter routes all logging through a process-wide mutable static, ApplicationLogging.LoggerFactory. The dependency-injection extensions copy the container's ILoggerFactory into this static when building the CommandProcessor and Dispatcher.

Because it is a single static, it is shared between two or more Brighter instances running in the same process — a common situation in parallel test suites (each test class spins up its own ServiceProvider).

This leads to two failures:

  1. Wrong logger from the wrong service provider. With two or more service providers, whichever Brighter initializes last overwrites the static. Code belonging to one instance then logs through the ILoggerFactory owned by a different service provider.

  2. Disposal breaks other running instances. When a ServiceProvider is disposed it disposes its ILoggerFactory. The static still holds a reference to that now-disposed factory, so other still-running Brighter instances can throw ObjectDisposedException (or silently log nowhere) the next time they log.

The net effect is that two or more Brighters cannot run cleanly side by side in the same process.

Expected

Logging should be instance-scoped: each Brighter instance logs through the ILoggerFactory of the service provider that created it, and disposing one instance must not affect another.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions