serilog-sinks-testcorrelator icon indicating copy to clipboard operation
serilog-sinks-testcorrelator copied to clipboard

Seems like multiple calls to CreateContext in the same thread just accumulates ContextGuids to the AsyncLocal

Open triple-vee opened this issue 4 years ago • 1 comments

And while GetLogEventsFromContextGuid() seems to reduce the number of LogEvent's in the result set (because a Dispose removes the ContextGuid from ContextGuids collection, GetLogEventsFromCurrentContext() doesn't look at the ContextGuids collection and seems to grab all the logs from the AsyncLocal collection.

This is problematic when running XUnit tests. All logs from all tests in the file end up in the same AsyncLocal collection. So the number of LogEvent's just grows as the test runner executes unit tests. It would be cool if there were a way to purge all the logs in AsyncLocal

triple-vee avatar Aug 03 '21 19:08 triple-vee

I'm going to debug this locally to see what's going on. Will post back later.

triple-vee avatar Aug 26 '21 18:08 triple-vee

I'm going to close this since it's been three years and I don't think there's a bug here. It's intentional that this library accumulates LogEvents since there is no way for us to know when the last time a LogEvent will be requested is. I think adding a purge method would cause more trouble than benefit, especially for parallel or async tests.

MitchBodmer avatar May 28 '24 05:05 MitchBodmer