public override async Task Invoke(IOwinContext context) { //serilog-seq configuration Log.Logger = new LoggerConfiguration() .WriteTo.Seq("http://localhost:5341") .CreateLogger(); //END Serilog LogRequestResponseHelper.LogDebugRequest(Logger, context.Request); var responseBody = ""; if (Logger.IsTraceEnabled) //use trace for logging the response { using (var captureResponseBody = new CaptureResponseBody(context)) { await Next.Invoke(context); responseBody = await captureResponseBody.GetBody(); } } else { await Next.Invoke(context); } /* * LogRequestResponseHelper.LogDebugResponse(Logger, context.Response); * if (Logger.IsTraceEnabled * && !string.IsNullOrEmpty(context.Response.ContentType) && context.Response.ContentType.ToLower().StartsWith("application/json")) * LogRequestResponseHelper.LogTraceResponse(Logger, responseBody); */ }
public override async Task Invoke(IOwinContext context) { LogRequestResponseHelper.LogDebugRequest(Logger, context.Request); var responseBody = ""; if (Logger.IsTraceEnabled) //use trace for logging the response { using (var captureResponseBody = new CaptureResponseBody(context)) { await Next.Invoke(context); responseBody = await captureResponseBody.GetBody(); } } else { await Next.Invoke(context); } LogRequestResponseHelper.LogDebugResponse(Logger, context.Response); if (Logger.IsTraceEnabled && !string.IsNullOrEmpty(context.Response.ContentType) && context.Response.ContentType.ToLower().StartsWith("application/json")) { LogRequestResponseHelper.LogTraceResponse(Logger, responseBody); } }
// ReSharper disable once AsyncConverter.AsyncMethodNamingHighlighting public override async Task Invoke(IOwinContext context) { Log.Information( "Method: {Method} Path: {Path}", context.Request.Method, context.Request.Path); using (var captureResponseBody = new CaptureResponseBody(context)) { using (LogContext.PushProperty("RequestId", Guid.NewGuid())) { await Next.Invoke(context).ConfigureAwait(false); } Log.Verbose("Response body: {Body}", await captureResponseBody.GetBodyAsync().ConfigureAwait(false)); } }