使用 Unity\T4\anything 进行面向方面的日志记录 [英] Aspect Oriented Logging with Unity\T4\anything else

查看:26
本文介绍了使用 Unity\T4\anything 进行面向方面的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我们有一个跟踪记录器.我们在大多数跟踪方法名称和参数值的重要方法的开头和结尾添加了日志语句.现在这些跟踪语句使代码变得臃肿,阅读它们有点痛苦.

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.

今天我正在阅读有关 Unity 的拦截框架的内容.如果可以使用通用记录器拦截我的方法调用并记录方法名称和参数值,我有一个想法.我不确定是否可以使用反射读取方法参数.Unity 可以这样使用吗?

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?

另一个想法是运行 T4 代码生成引擎,在所有装饰有特定属性的方法的开头和结尾生成日志语句.由于我对T4知之甚少,有没有人知道这是否可以实现?

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?

干杯,取消网格

推荐答案

使用 PostSharp.

他们还列出了许多替代http://www.sharpcrafters.com/postsharp/alternatives

这篇关于使用 Unity\T4\anything 进行面向方面的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆