BrighterCommand / BrighterCommand/Brighter

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

Open
#4,184 0 comments 0 reactions 2 assignees Claimed by @thomhurst View on GitHub
.NET 2 - In Progress Breaking Change feature request V11
Dominant language
C#
Stars
2.5k
Forks
296
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.