CollaboratingPlatypus / PetaPoco

Official PetaPoco, A tiny ORM-ish thing for your POCO's
Other
2.07k stars 601 forks source link

Log4Net integration #258

Open diegodfsd opened 8 years ago

diegodfsd commented 8 years ago

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

pleb commented 8 years ago

@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

diegodfsd commented 8 years ago

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.

enrico-padovani commented 8 years ago

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

xmedeko commented 8 years ago

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
};
diegodfsd commented 7 years ago

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.