PetaPoco icon indicating copy to clipboard operation
PetaPoco copied to clipboard

Log4Net integration

Open diegodfsd opened this issue 8 years ago • 5 comments

I'm using PetaPoco a few months and now I'm missing integration with log4net for example.

diegodfsd avatar Mar 01 '16 23:03 diegodfsd

@diegodfsd currently you would need to extended PetaPoco and override any of the OnExecutedCommand, OnExecutingCommand, OnException, OnConnectionOpened and OnConnectionClosing methods to implement logging. Obviously, this is not a great solution so I've added to the roadmap to make logging easier

pleb avatar Mar 02 '16 23:03 pleb

Thank you @pleb I will try think in a how to improve the obvious idea to add log. I'm waiting for a new version.

diegodfsd avatar Mar 04 '16 15:03 diegodfsd

I think this could lead to a general design on implementing hooks in the pipeline that can be plugged in for monitoring events and avoiding subclassing.

I believe an elegant way could be to have a similar concept of action filters in asp.net mvc. Doing so, you could implement your logging strategy by using attributes / implement specific interfaces.

Here I found some interesting ideas also: https://github.com/TrevorPilley/MicroLite/wiki/Listeners

enrico-padovani avatar Mar 04 '16 20:03 enrico-padovani

You can use slf4net. Or some projects just use their own simple logging façade which is possible to set up by some public static IMyLog Log property.

To @enrico-padovani comment: IMHO something like

public static Action<string> BeforeDelete;
public static Action AfterDelete;

etc. is simpler and enough solution. When somebody want to chain such Actions he may do it as he likes:

var old = BeforeDelete;
BeforeDelete = s => 
{
    // code

    if (old != null)
        old(s);

    // code
};

xmedeko avatar Mar 30 '16 09:03 xmedeko

Hello everyone! Just now I stopped to solve this problem and it is easiest than I thought. The Database class have some extension points and one of that is the OnException virtual method. Besides, there are others two methods OnExecutingCommand and OnExecutedCommand and you can use to debug your queries.

diegodfsd avatar Dec 01 '16 18:12 diegodfsd