From 320dfe846c32f37bd237aed53c3b9946a0e30863 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com>
Date: Thu, 4 Nov 2021 10:48:21 +0800
Subject: [PATCH] DisableRequestLogging
---
.../ApplicationBuilderExtensions.cs | 22 +++++++++++++++++--
FastGithub/Startup.cs | 7 +-----
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/FastGithub.HttpServer/ApplicationBuilderExtensions.cs b/FastGithub.HttpServer/ApplicationBuilderExtensions.cs
index fdcb4f4..afccc1d 100644
--- a/FastGithub.HttpServer/ApplicationBuilderExtensions.cs
+++ b/FastGithub.HttpServer/ApplicationBuilderExtensions.cs
@@ -17,13 +17,13 @@ namespace FastGithub
///
public static IApplicationBuilder UseServerHeader(this IApplicationBuilder app, string serverHeader = nameof(FastGithub))
{
- return app.Use(next => async context =>
+ return app.Use(next => context =>
{
if (context.Response.HasStarted == false)
{
context.Response.Headers.Server = serverHeader;
}
- await next(context);
+ return next(context);
});
}
@@ -49,6 +49,24 @@ namespace FastGithub
return app.Use(next => context => middleware.InvokeAsync(context, next));
}
+ ///
+ /// 禁用请求日志中间件
+ ///
+ ///
+ ///
+ public static IApplicationBuilder DisableRequestLogging(this IApplicationBuilder app)
+ {
+ return app.Use(next => context =>
+ {
+ var loggingFeature = context.Features.Get();
+ if (loggingFeature != null)
+ {
+ loggingFeature.Enable = false;
+ }
+ return next(context);
+ });
+ }
+
///
/// 使用反向代理中间件
///
diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs
index 927655f..411ef5d 100644
--- a/FastGithub/Startup.cs
+++ b/FastGithub/Startup.cs
@@ -1,6 +1,5 @@
using FastGithub.Configuration;
using FastGithub.FlowAnalyze;
-using FastGithub.HttpServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
@@ -68,15 +67,11 @@ namespace FastGithub
appBuilder.UseHttpReverseProxy();
appBuilder.UseRouting();
+ appBuilder.DisableRequestLogging();
appBuilder.UseEndpoints(endpoint =>
{
endpoint.MapGet("/flowStatistics", context =>
{
- var loggingFeature = context.Features.Get();
- if (loggingFeature != null)
- {
- loggingFeature.Enable = false;
- }
var flowStatistics = context.RequestServices.GetRequiredService().GetFlowStatistics();
return context.Response.WriteAsJsonAsync(flowStatistics);
});