Skip to content

Conversation

nblumhardt
Copy link
Member

Looking at this again, it would be too easy to violate the single-threadedness of DiagnosticContextCollector in the current design - there's no indication in the API of IDiagnosticContext that there are any constraints on how its called.

This PR introduces a simple mutex to make DiagnosticContextCollector thread-safe. There's a possibility this could be done lock-free, but that's probably fine to punt for a future iteration.

After the PR, the example in #9 (comment) will be correct/safe:

var collector = _diagnosticContext.BeginCollection();
var task = SomeMethodAsync();
collector.TryComplete(...);

@nblumhardt
Copy link
Member Author

Dropping in one more commit that switches Add() for Set() and updates existing values rather than extending the list of collected properties.

@nblumhardt
Copy link
Member Author

Still churning this feature a bit, and keen to get the changes integrated downstream while I have some time available. If everyone will forgive me the indiscretion, I'll merge now recklessly 😁 and push any changes from review feedback in a follow-up PR.

@nblumhardt nblumhardt merged commit 204fe13 into serilog:dev Jun 26, 2019
@nblumhardt nblumhardt mentioned this pull request Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant