我上课了:
public class GeoSalesLogger : ActionFilterAttribute
{
private Stopwatch timer;
private Request Argument;
public ILogger logger { get; set; }
public GeoSalesLogger()
{
}
public GeoSalesLogger(ILogger<GeoSalesLogger> logger)
{
logger = logger;
}
public override void OnActionExecuting(ActionExecutingContext filterContext){}
public override void OnActionExecuted(ActionExecutedContext filterContext){}
}
接下来我打电话给ather课程[GeoSalesLogger]
问题:如何在这里添加ILogger,因为我无法在构造函数中添加它。我也尝试使用autofuc
builder.RegisterType<GeoLogger>();
builder.RegisterFilterProvider();
和
DependencyResolver.Current.GetService<ILogger>();
如何在没有静电的情况下使用ILogger?
答案 0 :(得分:0)
您需要使用ActionFilterAttribute
来解决ActionExecutingContext
的记录器。
public override void OnActionExecuting(ActionExecutingContext context)
{
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<GeoSalesLogger>>();
...
}