Нема описа

LoggerServices.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  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. Queue<string> queue = new Queue<string>();
  21. try
  22. {
  23. await _next(context);
  24. }
  25. finally
  26. {
  27. Task Tinfo = new Task(() => _logger.AddAction($"{this.GetType().Name} -> {MethodBase.GetCurrentMethod()} -> {context?.Request?.Path ?? "Nothing"} -> {context?.Request?.Headers?.ToString() ?? "Nothing"} -> {context?.Request?.Host.Host ?? "Nothing"}", ref queue));
  28. Task Twrite = new Task(() => _logger.Write(queue));
  29. Tinfo.Start();
  30. Twrite.Start();
  31. }
  32. }
  33. }
  34. }

Powered by TurnKey Linux.