From 60d5ed76acc18d91dbe7e59418c2f1885d523b0a Mon Sep 17 00:00:00 2001 From: xljiulang <366193849@qq.com> Date: Sat, 12 Jun 2021 00:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=AB=E6=8F=8F=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=97=A5=E5=BF=97=E4=B8=AD=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub/GithubContext.cs | 2 +- FastGithub/Middlewares/HttpsScanMiddleware.cs | 2 -- FastGithub/Middlewares/ScanOkLogMiddleware.cs | 26 +++++++++++++++++++ FastGithub/Program.cs | 2 ++ FastGithub/appsettings.json | 3 +-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 FastGithub/Middlewares/ScanOkLogMiddleware.cs diff --git a/FastGithub/GithubContext.cs b/FastGithub/GithubContext.cs index b414e80..885f157 100644 --- a/FastGithub/GithubContext.cs +++ b/FastGithub/GithubContext.cs @@ -16,7 +16,7 @@ namespace FastGithub public override string ToString() { - return $"{Address}\t{Domain}\t#{HttpElapsed}"; + return $"{Address}\t{Domain}\t# {HttpElapsed}"; } } } diff --git a/FastGithub/Middlewares/HttpsScanMiddleware.cs b/FastGithub/Middlewares/HttpsScanMiddleware.cs index 39ec0c5..93a1574 100644 --- a/FastGithub/Middlewares/HttpsScanMiddleware.cs +++ b/FastGithub/Middlewares/HttpsScanMiddleware.cs @@ -46,8 +46,6 @@ namespace FastGithub.Middlewares if (server.Any(s => string.Equals("GitHub.com", s.Product?.Name, StringComparison.OrdinalIgnoreCase))) { context.HttpElapsed = DateTime.Now.Subtract(startTime); - this.logger.LogWarning(context.ToString()); - await next(); } } diff --git a/FastGithub/Middlewares/ScanOkLogMiddleware.cs b/FastGithub/Middlewares/ScanOkLogMiddleware.cs new file mode 100644 index 0000000..bd175bb --- /dev/null +++ b/FastGithub/Middlewares/ScanOkLogMiddleware.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; + +namespace FastGithub.Middlewares +{ + sealed class ScanOkLogMiddleware : IGithubMiddleware + { + private readonly ILogger logger; + + public ScanOkLogMiddleware(ILogger logger) + { + this.logger = logger; + } + + public Task InvokeAsync(GithubContext context, Func next) + { + if (context.HttpElapsed != null) + { + this.logger.LogWarning(context.ToString()); + } + + return next(); + } + } +} diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs index b22169c..2f84cad 100644 --- a/FastGithub/Program.cs +++ b/FastGithub/Program.cs @@ -36,12 +36,14 @@ namespace FastGithub .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton(serviceProvider => { return new GithubBuilder(serviceProvider, ctx => Task.CompletedTask) .Use() .Use() .Use() + .Use() .Build(); }) .AddHostedService() diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index a6690fc..44ee0af 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -8,8 +8,7 @@ "LogLevel": { "Default": "Information", "System": "Warning", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft": "Warning" } } }