RequestMiddleware.cs 988 B

123456789101112131415161718192021222324252627282930313233343536
  1. using Microsoft.AspNetCore.Http;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Threading.Tasks;
  5. namespace Ropin.Inspection.Api.Filters
  6. {
  7. /// <summary>
  8. /// 请求记录中间件
  9. /// </summary>
  10. public class RequestMiddleware
  11. {
  12. private readonly RequestDelegate _next;
  13. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(RequestMiddleware));
  14. public RequestMiddleware(RequestDelegate next)
  15. {
  16. this._next = next;
  17. }
  18. public RequestMiddleware() { }
  19. public async Task Invoke(HttpContext httpContext)
  20. {
  21. //启用读取request
  22. httpContext.Request.EnableBuffering();
  23. var request = httpContext.Request;
  24. //请求接口
  25. var reqUrl = request.Path;
  26. //
  27. Console.WriteLine(reqUrl);
  28. log.Info($"路径3:{reqUrl}");
  29. await _next(httpContext);
  30. }
  31. }
  32. }