Ejemplo n.º 1
0
        public async Task Invoke(HttpContext context, LogRequest logRequest)
        {
            var requestBodyStream   = new MemoryStream();
            var originalRequestBody = context.Request.Body;
            await context.Request.Body.CopyToAsync(requestBodyStream);

            requestBodyStream.Seek(0, SeekOrigin.Begin);
            logRequest.WriteLogRequest(requestBodyStream, context.Request.Headers);
            requestBodyStream.Seek(0, SeekOrigin.Begin);
            context.Request.Body = requestBodyStream;

            await _next.Invoke(context);

            context.Request.Body = originalRequestBody;
        }