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); });