开发者

Common.Logging - how to get callback on log writing?

开发者 https://www.devze.com 2023-03-08 23:07 出处:网络
I 开发者_开发百科have a library, which uses Common.Logging. I need to get my code called when any write to it\'s log occurs.If you don\'t want change anything you could use AOP to intercept the method

I 开发者_开发百科have a library, which uses Common.Logging. I need to get my code called when any write to it's log occurs.


If you don't want change anything you could use AOP to intercept the method call to the Common.Logging but bear in mind the AOP add lots of overhead as behind the scene it injects code at run time.Otherwise you could wrap/Extend the Common.Loggin and create your own Write method that invoke a delegate that will point at the code you want to be executed(kind of callback)


if your logging has been designed to an interface, you can use Decorator pattern to create new Logging which will internally call the original Logging.

And then you can register your new DecoratorLogging against ILogging (via dependency injection) that you have so that any consumers of the ILogging will not know that they are actually using your new logger :)


Setting my own adapter into LogManager.Adapter worked ok.

0

精彩评论

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