danieleteti / loggerpro

An modern and pluggable logging framework for Delphi
Apache License 2.0
352 stars 91 forks source link

Database Appender #88

Closed fastbike closed 5 months ago

fastbike commented 6 months ago

I have created a simple database appender to write log files to a database. Because we are currently using dbGo (ADO) coomponents to connect to a MS SQL Server I did the initial work using that connection stack.

As we are planning on migrating to FireDAC, I have refactored into a base class and created two child classes - one for ADO and one for FireDAC.

Due to security considerations I have used stored procedures.

One thing I am looking at it the retry mechanism, as occasionally a DB call may not succeed so a retry is often warranted. I see the TryToRestart virtual method but this just seems the reset the logging thread while discarding the actual logItem. Is there some guidance around retries (I could imagine this would happen with REST providers too) so I can refactor this before sharing the code.

danieleteti commented 5 months ago

Thank you for your contribution, David. I added the FireDACDBAppender with an example for postgresql. There is a ddl script to create all the needed db objects to run the sample. Regarding the logitem discard, I added a fallback logger to not loose nothing. However, we could just mantain the log in the queue, but this is a false solution because the queue will eventually gets full. Please, let me know if the changes work for you.

fastbike commented 5 months ago

Thanks for adding the FireDAC examples and enhancing the fallback logging - I found your code educational :) I'm happy to close this ticket.