private static void PushInfoToContext(HttpContext httpContext, ICorrelationIdProvider correlationIdProvider) { LogContext.PushProperty("Info", new { MachineName = Environment.MachineName, ClientIP = httpContext.Connection.RemoteIpAddress, RequestId = Guid.NewGuid(), CorrelationId = correlationIdProvider.EnsureCorrelationIdPresent() }); }
public async Task InvokeAsync(HttpContext context, FunctionRequestDelegate next) { var correlation = _correlationIdProvider.EnsureCorrelationIdPresent(); var request = context.Request; var response = context.Response; request.Headers.TryGetValue(KnownHttpHeaders.CorrelationId, out StringValues requestHeaderValue); if (requestHeaderValue.FirstOrDefault() == null) { request.Headers.Add(KnownHttpHeaders.CorrelationId, correlation); } response.Headers.TryGetValue(KnownHttpHeaders.CorrelationId, out StringValues responseHeaderValue); if (responseHeaderValue.FirstOrDefault() == null) { response.Headers.Add(KnownHttpHeaders.CorrelationId, correlation); } await next(context); }