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" } } }