intelligentplant / AppStoreConnect.Adapters

Allows Intelligent Plant App Store Connect to query 3rd party systems
https://appstore.intelligentplant.com
MIT License
0 stars 0 forks source link

Logging scopes rework #379

Closed wazzamatazz closed 5 months ago

wazzamatazz commented 5 months ago

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.