mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 22:08:17 +08:00
small changes to log all responses either information or warning
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Requester.Middleware
|
||||
{
|
||||
@ -22,6 +25,8 @@ namespace Ocelot.Requester.Middleware
|
||||
{
|
||||
var response = await _requester.GetResponse(context);
|
||||
|
||||
CreateLogBasedOnResponse(response);
|
||||
|
||||
if (response.IsError)
|
||||
{
|
||||
Logger.LogDebug("IHttpRequester returned an error, setting pipeline error");
|
||||
@ -36,5 +41,19 @@ namespace Ocelot.Requester.Middleware
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
|
||||
private void CreateLogBasedOnResponse(Response<HttpResponseMessage> response)
|
||||
{
|
||||
if (response.Data?.StatusCode <= HttpStatusCode.BadRequest)
|
||||
{
|
||||
Logger.LogInformation(
|
||||
$"{(int)response.Data.StatusCode} ({response.Data.ReasonPhrase}) status code, request uri: {response.Data.RequestMessage?.RequestUri}");
|
||||
}
|
||||
else if (response.Data?.StatusCode >= HttpStatusCode.BadRequest)
|
||||
{
|
||||
Logger.LogWarning(
|
||||
$"{(int) response.Data.StatusCode} ({response.Data.ReasonPhrase}) status code, request uri: {response.Data.RequestMessage?.RequestUri}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user