Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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

like image 266
Unmesh Kondolikar Avatar asked Sep 03 '10 05:09

Unmesh Kondolikar


1 Answers

Use PostSharp.

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

like image 57
Preet Sangha Avatar answered Sep 27 '22 19:09

Preet Sangha