Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create Serilog Enricher to add Request header in logs
public class CorrelationIdEnricher : ILogEventEnricher
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (HttpContext.Current == null)
if (HttpContext.Current.Request == null)
string correlationId = HttpContext.Current.Request.Headers["CorrelationId"];
if (string.IsNullOrWhiteSpace(correlationId))
var correlationIdProperty = new LogEventProperty("CorrelationId", new ScalarValue(correlationId));
Copy link

vetras commented Aug 9, 2017

this helped :D

Copy link

elena-posea commented Nov 20, 2017

this was also helpful for me, as I had a custom header to look for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment