serilog-enrichers-clientinfo
                                
                                
                                
                                    serilog-enrichers-clientinfo copied to clipboard
                            
                            
                            
                        NullReferenceException for CorrelationId when targeting .NET Framework
When using the CorrelationIdEnricher and targeting .NET framework, a NullReferenceException will occur here:
var header = httpContext.Request.Headers[_headerKey].ToString();
Because httpContext.Request.Headers[_headerKey] is actually null. The next line is:
   var correlationId = !string.IsNullOrWhiteSpace(header)
       ? header
       : (_addValueIfHeaderAbsence ? Guid.NewGuid().ToString() : null);
This is a bit strange. You should call .ToString() after the null check, don't you?
This code works fine in .NET Core and unfortunately, there is no way that I can implement unit tests for enrichers when the target framework is .NET Framework and the reason is that HttpCaontext.Current is a static class and mocking it is extremely hard. For the next release, I will drop support for .NET Framework.