Forked from stevejgordon/CorrelationIdMiddleware.cs
Last active
July 3, 2018 15:29
-
-
Save dontjee/8ffab0fe9e0ef9a8881393fef410f5e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CorrelationIdMiddleware | |
{ | |
private readonly RequestDelegate _next; | |
public CorrelationIdMiddleware(RequestDelegate next) | |
{ | |
_next = next ?? throw new ArgumentNullException(nameof(next)); | |
} | |
public Task Invoke(HttpContext context) | |
{ | |
if (context.Request.Headers.TryGetValue("X-Correlation-Id", out StringValues correlationId)) | |
{ | |
context.TraceIdentifier = correlationId; | |
} | |
return _next(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment