增加扫描结果日志中间件

This commit is contained in:
xljiulang 2021-06-12 00:36:33 +08:00
parent c86e37172f
commit 60d5ed76ac
5 changed files with 30 additions and 5 deletions

View File

@ -16,7 +16,7 @@ namespace FastGithub
public override string ToString()
{
return $"{Address}\t{Domain}\t#{HttpElapsed}";
return $"{Address}\t{Domain}\t# {HttpElapsed}";
}
}
}

View File

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

View File

@ -0,0 +1,26 @@
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace FastGithub.Middlewares
{
sealed class ScanOkLogMiddleware : IGithubMiddleware
{
private readonly ILogger<ScanOkLogMiddleware> logger;
public ScanOkLogMiddleware(ILogger<ScanOkLogMiddleware> logger)
{
this.logger = logger;
}
public Task InvokeAsync(GithubContext context, Func<Task> next)
{
if (context.HttpElapsed != null)
{
this.logger.LogWarning(context.ToString());
}
return next();
}
}
}

View File

@ -36,12 +36,14 @@ namespace FastGithub
.AddSingleton<PortScanMiddleware>()
.AddSingleton<HttpsScanMiddleware>()
.AddSingleton<ConcurrentMiddleware>()
.AddSingleton<ScanOkLogMiddleware>()
.AddSingleton(serviceProvider =>
{
return new GithubBuilder(serviceProvider, ctx => Task.CompletedTask)
.Use<ConcurrentMiddleware>()
.Use<PortScanMiddleware>()
.Use<HttpsScanMiddleware>()
.Use<ScanOkLogMiddleware>()
.Build();
})
.AddHostedService<GithubHostedService>()

View File

@ -8,8 +8,7 @@
"LogLevel": {
"Default": "Information",
"System": "Warning",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft": "Warning"
}
}
}