美好的一天。
我正在尝试通过在我的自定义 ActionFilterAttribute 类中注入 LoggerFactory 来使用日志记录,但是在控制器方法之一中使用 Attribute 时,我收到一条错误消息
[CS7036] There is no argument given that corresponds to the required formal parameter 'logger' of 'Tracker.Tracker(ILoggerFactory)'
下面是这个类的实现:
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);
}
}
}
当我尝试在控制器中使用跟踪器时出现上述错误,如下所示:
[Tracker(ActionType="testType", ActionName="testName")]
public IActionResult Index()
{
return View();
}
可以做些什么来修复错误?
缥缈止盈
相关分类