No Description

LoggerServices.cs 967B

1234567891011121314151617181920212223242526272829303132333435
  1. using Logger.Services.Interfaces;
  2. using Microsoft.AspNetCore.Http;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace Logger.Services
  9. {
  10. public class LoggerServices
  11. {
  12. private readonly RequestDelegate _next;
  13. public LoggerServices(RequestDelegate next)
  14. {
  15. _next = next;
  16. }
  17. public async Task Invoke(HttpContext context, IMonLogger _logger)
  18. {
  19. context ??= new DefaultHttpContext();
  20. try
  21. {
  22. _logger.AddAction($"{this.GetType().Name} -> {context?.Request?.Method} -> {context?.Request?.Path} -> {context?.Request?.Headers} -> {context?.Request?.Host}");
  23. await _next(context);
  24. }
  25. finally
  26. {
  27. Task Twrite = new Task(() => _logger.Write());
  28. Twrite.Start();
  29. }
  30. }
  31. }
  32. }

Powered by TurnKey Linux.