2
0

ScanOkLogMiddleware.cs 738 B

12345678910111213141516171819202122232425262728
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.Logging;
  3. using System;
  4. using System.Threading.Tasks;
  5. namespace FastGithub.Scanner.Middlewares
  6. {
  7. [Service(ServiceLifetime.Singleton)]
  8. sealed class ScanOkLogMiddleware : IGithubScanMiddleware
  9. {
  10. private readonly ILogger<ScanOkLogMiddleware> logger;
  11. public ScanOkLogMiddleware(ILogger<ScanOkLogMiddleware> logger)
  12. {
  13. this.logger = logger;
  14. }
  15. public Task InvokeAsync(GithubContext context, Func<Task> next)
  16. {
  17. if (context.HttpElapsed != null)
  18. {
  19. this.logger.LogInformation(context.ToString());
  20. }
  21. return next();
  22. }
  23. }
  24. }