Aop、Unity、拦截器和 ASP.NET MVC 控制器操作方法
使用 log4net,我们希望记录对 ASP.NET MVC 控制器操作方法的所有调用。
日志应包含有关传递给控制器的任何参数的信息。
我们希望使用带有 的 AoP 方法,而不是在每个操作方法中手动编码。通过 Unity 拦截器。
我们已经将其与其他一些使用接口的类一起使用(使用InterfaceInterceptor)。但是,我们不确定如何继续使用我们的控制器。我们是否应该稍微重新设计它们以使用界面,或者是否有更简单的方法?
编辑
VirtualMethodInterceptor 似乎是正确的方法,但是使用此方法会导致以下异常:
System.ArgumentNullException: Value cannot be null. Parameter name: str at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, String str) at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
Using log4net we would like to log all calls to our ASP.NET MVC controller action methods.
The logs should include information about any parameters that were passed to the controller.
Rather than hand-coding this in each action method we hope to use an AoP approach with Interceptors via Unity.
We already have this working with some other classes that use interfaces (using the InterfaceInterceptor
). However, we're not sure how to proceed with our controllers. Should we re-work them slightly to use an interface, or is there a simpler approach?
Edit
The VirtualMethodInterceptor seems to be the correct approach, however using this results in the following exception:
System.ArgumentNullException: Value cannot be null. Parameter name: str at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, String str) at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您看过
这个[链接损坏]以下是由 David Hayden 提供的损坏/丢失博客文章的摘录
这是一个使用企业库日志记录应用程序块<的
LogFilterAttribute
/strong> 的LogWriter
用于记录消息。Have you seen
this[link broken]Following is an excerpt from the broken/missing blog post courtesy of David Hayden
Here is a
LogFilterAttribute
that uses the Enterprise Library Logging Application Block'sLogWriter
for logging messages.不完全是您所要求的,但您可能需要考虑 log4postsharp。也许您还需要这个,但我不知道当然,因为到目前为止我还没有使用 ASP.Net MVC
not exactly what you are asking, but you might want to consider log4postsharp. maybe you will need this as well, but I cannot tell for sure as I did not use ASP.Net MVC so far