Castle:如何在日志拦截器中获取正确的 ILogger?
如果您在温莎城堡中使用 LoggingFacility,如果您的类中有可选的记录器依赖项(城堡可以将记录器注入其中的 ILogger 属性),容器将自动解析与您的类关联的记录器,但是如果我想使用AOP(拦截器方法)来实现日志记录?我基本上想写这样的东西:
public void Intercept(IInvocation invocation)
{
ILogger logger = LogManager.GetLogger(invocation.TargetType);
//..
}
但是Castle框架中没有LogManager可言。解决这个问题的最佳方法是什么?我应该忽略工具方法并直接在拦截器中使用 log4net 吗?
If you are using the LoggingFacility in Castle Windsor the container will automatically resolve the logger associated with your class if you have optional logger dependencies in your class (an ILogger property that castle can inject the logger into), but how can I leverage the facility if I want to implement the logging using AOP (interceptor approach)? I basically want to write something like:
public void Intercept(IInvocation invocation)
{
ILogger logger = LogManager.GetLogger(invocation.TargetType);
//..
}
But there is no LogManager to speak of in the Castle framework. What is the best approach to solving this? Should I just ignore the facility approach and use log4net directly in the interceptor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在构造函数中依赖 Castle.Core.Logging.ILoggerFactory 并在 Intercept 方法中从工厂创建记录器
Take a dependency on Castle.Core.Logging.ILoggerFactory in your constructor and create the logger from the factory in the Intercept method