Closed pavel-faltynek closed 1 month ago
Anyway, conversion to using var
might probably work (even if it temporarily changes the provider's scope chain). As the provider's scope is async-local, it might be also resistant to concurrency issues.
Thanks for checking this out, @pavel-faltynek, I think this is an issue 👍
We should be able to pull most of EnrichAndCreateScopeItem()
out into a static method that avoids tinkering with the current scope or allocating.
I can take a look at this, but let me know if you're keen to dig in, all help appreciated.
Ok, tried in https://github.com/serilog/serilog-extensions-logging/pull/252, could you please check it does make sense to you?
Is it intended that the code utilizing scopes provided by
IExternalScopeProvider
is modifying theSerilogLoggerProvider
's current scope chain via creating (and not disposing)SerilogLoggerScope
every time aLogEvent
is enriched?https://github.com/serilog/serilog-extensions-logging/blob/3c329978b208b15a5bc80f1204cdb14b64f5effe/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs#L81
Does not feel correct at first sight. It captures provider's current source and replaces it by itself, which seems to be intended to reverse on
Dispose()
(which is never called). Should it even manipulate the provider's scope chain at all? Shouldn't it just enrich theLogEvent
via scopes from external source without performing any side effects?