使用 Unity\T4\anything 进行面向方面的日志记录
在我的应用程序中,我们有一个跟踪记录器。我们在大多数重要方法的开头和结尾添加了日志语句,用于跟踪方法名称和参数值。现在这些跟踪语句使代码变得臃肿,阅读它们有点痛苦。
我正在考虑如何将代码的这方面与我的业务逻辑分开。
今天在读Unity的拦截框架。我突然想到是否可以使用通用记录器拦截我的方法调用并记录方法名称和参数值。我不确定是否可以使用反射读取方法参数。 Unity可以这样用吗?
另一个想法是运行 T4 代码生成引擎,在用特定属性修饰的所有方法的开头和结尾生成日志记录语句。由于我对T4知之甚少,有谁知道这是否可以实现?
还有其他方法可以将日志记录代码与我的业务逻辑分开吗?
干杯, 取消网格划分
In my application we have a trace logger. We have log statements added at the beginning and end of most of the important methods tracing the method name and the parameter values. Now these trace statements are bloating the code and it is a bit of a pain to read through them.
I am considering how can I separate this aspect of the code from my business logic.
Today I was reading about Unity's interception framework. I had a passing thought if it is possible to intercept my method calls with a generic logger and log the method name and parameter values. I am not sure if it is possible to read method parameters using reflection. Can Unity be used like this?
Another idea was to run the T4 code generation engine to generate logging statements at the beginning and end of all methods decorated with a particular attribute. Since I know very little about T4, does anyone know if this can be accomplished?
Are there any other ways to separate the logging code from my business logic?
Cheers,
Unmesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 PostSharp。
他们还列出了许多替代http://www.sharpcrafters.com/postsharp/alternatives
Use PostSharp.
They also list lots of alternative http://www.sharpcrafters.com/postsharp/alternatives
是的,您可以使用 Unity,但您应该使用 Unity“拦截扩展”。 这里有一篇好文章
Yes, You can use Unity but you should user Unity "Interception extension". nice article here