C# 将Ninject log4net注入到自定义FilterAttribute的属性中
我创建了一个自定义LogFilterAttribute,并希望将ILog对象注入Logger属性。调试项目时,ActionFilterAttribute的属性记录器为nullC# 将Ninject log4net注入到自定义FilterAttribute的属性中,c#,ninject,log4net,C#,Ninject,Log4net,我创建了一个自定义LogFilterAttribute,并希望将ILog对象注入Logger属性。调试项目时,ActionFilterAttribute的属性记录器为null public class LogFilterAttribute : ActionFilterAttribute { /// <summary> /// Get or sets the value of the logger object /// </summary>
public class LogFilterAttribute : ActionFilterAttribute
{
/// <summary>
/// Get or sets the value of the logger object
/// </summary>
public ILog Logger { get; internal set; }
//some loggging with the Logger Property in the overriden methods
}
公共类LogFilterAttribute:ActionFilterAttribute
{
///
///获取或设置记录器对象的值
///
公共ILog记录器{get;internal set;}
//在重写的方法中使用Logger属性进行一些日志记录
}
我在方法RegisterServices的NinjectWeCommon.cs中注册注入
kernel.Bind<LogFilterAttribute>().ToSelf().WithPropertyValue("Logger", LogManager.GetLogger(typeof(Global)));
kernel.Bind().ToSelf().WithPropertyValue(“Logger”,LogManager.GetLogger(typeof(Global));
当我连接到LogFilterAttribute中的调试器时,属性Logger为null。我如何解决这个问题
(配置在web.config中设置)
问候语您是将此属性应用于控制器/操作还是将其添加到全局筛选器集合?我将此属性应用于webapi控制器/操作。似乎有:use。文档似乎已过时。我使用的是Ninject 3.2.0.0,编译器告诉我没有BindFilter方法。我试着跟着这个。但目前我无法修复它。我想我记得我读过一篇文章,说过滤器不是由容器实例化的。但是,它们似乎通过在属性上放置
[Inject]
属性来支持属性注入。看见