i have an action filter where i am trying to log name of action that system enters and left.
public class LogFilter : IAsyncActionFilter
{
private readonly ILogger<LogFilter > _logger;
public LogFilter(ILogger<LogFilter > logger)
{
_logger = logger;
}
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
_logger.LogInformation("Entering " + context.ActionDescriptor.ToString());
// execute any code before the action executes
var result = await next();
// execute any code after the action executes
_logger.LogInformation("Exiting " + context.ActionDescriptor.ToString());
}
}
but when i have to register this action Filter globally
services.AddControllers(config =>
{
config.Filters.Add(new LogFilter (how to pass ilogger));
});
what should i pass in the constructor ?