面向方面的记录与统一\ T4 \别的别的、方面

由网友(别低头皇冠会掉)分享简介:在我的应用程序,我们有一个跟踪记录器。我们已经登录在最重要的方法的跟踪的方法名称和参数值的开始和结束时加入语句。现在,这些跟踪语句腹胀code,这是一个有点疼痛通读它们。In my application we have a trace logger. We have log statements added at...

在我的应用程序,我们有一个跟踪记录器。我们已经登录在最重要的方法的跟踪的方法名称和参数值的开始和结束时加入语句。现在,这些跟踪语句腹胀code,这是一个有点疼痛通读它们。

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.

我在考虑我怎么能分开的code这方面从我的商业逻辑。

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?

另一个想法是运行的T4 code生成引擎生成在装饰有特定属性的所有方法的开始和结束记录语句。因为我不是很了解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?

还有没有其他的方法可以从我的业务逻辑分离的记录code?

Are there any other ways to separate the logging code from my business logic?

干杯, Unmesh

Cheers, Unmesh

推荐答案

使用 PostSharp 。

他们还列出了大量的替代 http://www.sharpcrafters.com/postsharp/alternatives

They also list lots of alternative http://www.sharpcrafters.com/postsharp/alternatives

阅读全文

相关推荐

最新文章