LFlow/LFlow.Middleware/Middlewares/LoggingMiddleware.cs

29 lines
912 B
C#
Raw Normal View History

2024-11-01 16:45:39 +08:00
namespace LFlow.Middleware.Middlewares
{
public class LoggingMiddleware : ILFlowMiddleware
{
private readonly ILogger<LoggingMiddleware> _logger;
public LoggingMiddleware(ILogger<LoggingMiddleware> logger)
{
_logger = logger;
}
public int Priority => 1;
public async Task RunAsync(HttpContext context, Func<Task> next)
{
var controllerName = context.GetRouteData()?.Values["controller"]?.ToString();
var actionName = context.GetRouteData()?.Values["action"]?.ToString();
using (_logger?.BeginScope("LoggingMiddleware"))
{
//_logger?.LogInformation($"Controller: {controllerName} / Action : {actionName}");
//_logger?.LogInformation("Router Data {@routerData}", context.GetRouteData());
await next();
}
}
}
}