public async Task Invoke(HttpContext context, IRequestTrace requestTracer) { var requestId = Guid.NewGuid(); requestTracer.Register(requestId); try { LogRequestData(context, requestId); await _next(context); LogResponseData(context, requestId); } catch (Exception exception) { _logger.LogError(exception, requestId + ": " + exception.Message); } }
public async Task Invoke(HttpContext context, IRequestTrace requestTracer) { var requestId = Guid.NewGuid(); requestTracer.Register(requestId); try { await LogRequestData(context, requestId); var originalBodyStream = context.Response.Body; await using var responseBody = new MemoryStream(); context.Response.Body = responseBody; await _next(context); await LogResponseData(context.Response, requestId); await responseBody.CopyToAsync(originalBodyStream); } catch (Exception exception) { _logger.LogError(exception, requestId + ": " + exception.Message); } }