Good day.
I'm trying to use logging by injecting a LoggerFactory in my custom ActionFilterAttribute class but when using the Attribute in one of the controller methods I get an error saying
[CS7036] There is no argument given that corresponds to the required formal parameter 'logger' of 'Tracker.Tracker(ILoggerFactory)'
Here's the implementation of the class:
using System;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
namespace ImmoSales.Tracking
{
public class Tracker : ActionFilterAttribute
{
public string ActionType { get; set; }
public string ActionName { get; set; }
private readonly ILoggerFactory _logger;
public Tracker(ILoggerFactory logger)
{
_logger = logger;
}
public override void OnActionExecuting(ActionExecutingContext context)
{
base.OnActionExecuting(context);
}
public override void OnActionExecuted(ActionExecutedContext context)
{
base.OnActionExecuted(context);
}
public override void OnResultExecuting(ResultExecutingContext context)
{
base.OnResultExecuting(context);
}
public override void OnResultExecuted(ResultExecutedContext context)
{
base.OnResultExecuted(context);
}
}
}
I get the mentioned error when I attempt to use the Tracker in a controller as follows:
[Tracker(ActionType="testType", ActionName="testName")]
public IActionResult Index()
{
return View();
}
What can be done to fix the error?