This is related to this question. Context: .Net Core 3.1, using Microsoft.Extensions.Logging
Loggers are singletons in the application's IHost
. If I inject (DI) an ILogger<T>
into my class or method, the injected object is the same instance other classes or methods receive if they ask for ILogger<T>
. This poses the question of what happens when I use logger.BeginScope($"Processing {transactionId}")
in one thread. What happens with the other threads? Do they change the logging scope as well? Do logging scopes get mixed up? If they don't: how does that work, being their loggers the same object? If they do mix scopes, how can I make two threads use different logging scopes for a given ILogger<T>
type?