Closed 30akuma41 closed 4 years ago
Not 100% if this fixes the issue without breaking other logic within the extension but I added the following code in the CorrelationIdHeaderEnricher and it seems to work.
var correlationId = string.IsNullOrEmpty(header) ? GetOrCreateCorrelationIdByItemName() <-- replaced Guid.NewGuid().ToString() : header;
The method used is similar to GetCorrelationId from CorrelationIdEnricher class
private string GetOrCreateCorrelationIdByItemName() { return (string)(_contextAccessor.HttpContext.Items[CorrelationIdItemName] ?? (_contextAccessor.HttpContext.Items[CorrelationIdItemName] = Guid.NewGuid().ToString())); }
and of course private static readonly string CorrelationIdItemName = $"{typeof(CorrelationIdHeaderEnricher).Name}+CorrelationId";
was added as well.
Please let me know if this is acceptable, or if other problems could arise if this change (or something similar) takes place.
https://github.com/ekmsystems/serilog-enrichers-correlation-id/pull/33/files#diff-e4f3e565f0c3341e91e28b282cd1925eR51 Here I introduce a much simpler way to retrieve already created correlationId when it was not supplied.
Merged #33 which should fix this. Thanks @lkurzyniec. 👍 I'll push a new release tonight.
Released as v3.0.1 so I'm gonna close this one off. Feel free to reopen if there are any issues. 👍
Hi, it seems that if no header is found in WithCorrelationIdHeader() then a new Guid is being created (which is correct), but for each log event it seems that it creates a new one every time, resulting in a no correlation between the event logs.
Unless I misunderstood something in the documentation, shouldn't the fallback functionality work as WithCorrelationId() method if no header is found? That is to create a new correlation id and keep that id the same for all event logs?