The previous approach to creating scoped ILogger instances was to create long-lived logger scopes that were created when the adapter was constructed and disposed when the adapter was disposed. Logger scope implementations usually use AyncLocal<T> to store the current logger scope, but this can get lost in IAsyncEnumerable methods for example.
To try and address this problem, this PR removes the ScopedLogger and ScopedLoggerFactory classes and instead provides helper methods on AdapterCore for creating logger scopes that set a state object containing the ID of the adapter. The onus to create and manage the lifetime of the scope is transferred to the types making the logging calls. Helper classes have been updated to create and dispose of scopes at appropriate times.
The previous approach to creating scoped
ILogger
instances was to create long-lived logger scopes that were created when the adapter was constructed and disposed when the adapter was disposed. Logger scope implementations usually useAyncLocal<T>
to store the current logger scope, but this can get lost in IAsyncEnumerable methods for example.To try and address this problem, this PR removes the
ScopedLogger
andScopedLoggerFactory
classes and instead provides helper methods onAdapterCore
for creating logger scopes that set a state object containing the ID of the adapter. The onus to create and manage the lifetime of the scope is transferred to the types making the logging calls. Helper classes have been updated to create and dispose of scopes at appropriate times.