-
Notifications
You must be signed in to change notification settings - Fork 822
Description
Background and motivation
FakeLoggerProvider currently allows the creation of non-generic loggers using:
var logger = loggerProvider.CreateLogger("CustomLogger");
However, it does not support creating generic loggers of type FakeLogger<T>
, which can be useful when testing logging behavior in a type-safe manner. By allowing generic loggers, we can ensure that FakeLogger instances share a common FakeLogCollector
, as well as a common IExternalScopeProvider
, thereby providing a consistent log collection and scope management experience across generic and non-generic loggers.
Adding support for CreateLogger<T>()
will improve usability and consistency in unit tests and middleware scenarios where logging is commonly scoped to specific types.
API Proposal
New Method in FakeLoggerProvider
public FakeLogger<T> CreateLogger<T>();
Signature Details:
T
: The type for which the logger is created.- Returns: An instance of
FakeLogger<T>
that utilizes the sharedFakeLogCollector
andIExternalScopeProvider
.
API Usage
var loggerProvider = new FakeLoggerProvider();
var logger = loggerProvider.CreateLogger<MyMiddleware>();
Alternative Designs
No response
Risks
No response