开发者

Aspect Oriented Logging with Unity\T4\anything else

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 c开发者_高级运维onsidering 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


Use PostSharp.

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


Yes, You can use Unity but you should user Unity "Interception extension". nice article here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜