public async Task Invoke(HttpContext context) { EnsureArg.IsNotNull(context, nameof(context)); HttpRequest request = context.Request; string startLogMessage = await GetStartLogMessageAsync(request); _logger.LogInformation(startLogMessage); (string responseBody, ExceptionDispatchInfo exceptionInfo) = await _next.TryRunAsync(context); string completeLogMessage = GetCompleteLogMessage(request, context.Response, responseBody, exceptionInfo?.SourceException); _logger.LogInformation(completeLogMessage); exceptionInfo?.Throw(); }