design patterns - Cross cutting concern logging -
i want log information methods being executed, considered aop okay, knocked demo, need log specific information each method, think of additional info related call.
now options considered log in each method, think going pollute code, last resort, perhaps
or create class maps methods information needs logged, , use aop log info.
what guys think?
an alternative approach might decorator pattern/interceptor pattern results in increased coding effort:
interface icomponent { int foo(int input); } class component : icomponent { public int foo(int input) { return input * 2; } } class loggingcomponent: icomponent { private readonly icomponent target; public loggingcomponent(icomponent target) { this.target = target; } public int foo(int input) { // todo: add logging before method call int returnvalue = this.target.foo(input); // todo: add logging after method call return returnvalue; } }
using approach requires implementing lot of logging classes targets want log method calls , input/return values. in addition can not log happens inside methods of target decorator/interceptor forwards to.
Comments
Post a Comment