From ed4978a6f6a070c07f8fec48542b50993704595f Mon Sep 17 00:00:00 2001
From: xljiulang <366193849@qq.com>
Date: Mon, 19 Jul 2021 21:26:46 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97=E4=B8=AD?=
=?UTF-8?q?=E9=97=B4=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FastGithub.ReverseProxy/RequestLoggingMilldeware.cs | 8 +++++---
FastGithub.ReverseProxy/ReverseProxyMiddleware.cs | 6 +++---
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs b/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs
index 3a454eb..95cf4c1 100644
--- a/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs
+++ b/FastGithub.ReverseProxy/RequestLoggingMilldeware.cs
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
+using System;
using System.Diagnostics;
using System.Threading.Tasks;
@@ -45,13 +46,14 @@ namespace FastGithub.ReverseProxy
var response = context.Response;
var message = $"{request.Method} {request.Scheme}://{request.Host}{request.Path} responded {response.StatusCode} in {stopwatch.Elapsed.TotalMilliseconds} ms";
- if (500 <= response.StatusCode && response.StatusCode <= 599)
+ var exception = context.GetForwarderErrorFeature()?.Exception;
+ if (exception == null)
{
- this.logger.LogError(message);
+ this.logger.LogInformation(message);
}
else
{
- this.logger.LogInformation(message);
+ this.logger.LogError($"{message}{Environment.NewLine}{exception.Message}");
}
}
}
diff --git a/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs b/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs
index dec5eb4..1c1cb21 100644
--- a/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs
+++ b/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs
@@ -60,7 +60,7 @@ namespace FastGithub.ReverseProxy
using var httpClient = new HttpClient(this.httpClientHanlder, tlsSniPattern);
var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient, requestConfig);
- await ResponseErrorAsync(context, error);
+ await HandleErrorAsync(context, error);
}
}
@@ -85,12 +85,12 @@ namespace FastGithub.ReverseProxy
}
///
- /// 写入错误信息
+ /// 处理错误信息
///
///
///
///
- private static async Task ResponseErrorAsync(HttpContext context, ForwarderError error)
+ private static async Task HandleErrorAsync(HttpContext context, ForwarderError error)
{
if (error == ForwarderError.None)
{