Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I log without polluting method?

Tags:

c#

logging

c#-4.0

I know about AOP and Postsharp but here the constraint is I can't use postsharp and using attributes for logging is having performance overhead.

But again right now I have to put log code in everymethod, a lot of copy paste and also it is not part of method. So, my functions are doing more than one work. It is somewhat not looks good to have business logic and log together.

Is there anyway out, like to make class open ended and can add log from out side of the class or function. Or I just have to go with traditional way of logging.

Please, let me know if any further information needed. Any suggestion of good/ another way of logging is also welcomed.

like image 433
kunjee Avatar asked Nov 03 '22 01:11

kunjee


2 Answers

Enterprise Library and Unity. You can use composition to create logging decorators around other classes that log then pass-through to the other class.

Check out msdn.microsoft.com/en-us/magazine/gg490353.aspx

like image 166
Peter Ritchie Avatar answered Nov 14 '22 01:11

Peter Ritchie


Hi as Peter Ritchie told, http://msdn.microsoft.com/en-us/magazine/gg490353.aspx is good solution. You can aslo take a look at http://www.microsoft.com/en-us/download/details.aspx?id=17866 or to other DI framework like Ninject this is good one for MVC projects. Any way this is good articale about DI perfomance http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison.

like image 42
Arbejdsglæde Avatar answered Nov 14 '22 02:11

Arbejdsglæde