Aspect Oriented Logging with Unity\T4\anything els

2019-02-17 02:32发布

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

2条回答
欢心
2楼-- · 2019-02-17 02:39

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

查看更多
再贱就再见
3楼-- · 2019-02-17 02:59
登录 后发表回答