0

Is any way to override SendBuffer method in AdoNetAppender to bulk insert logs in database? in below this link in SendBuffer method log4net write logs in database by iteration over loggingevent and insert each of them in separated query, I wanna insert all logs in a query, i think this approach increase performance.

Behrooz
  • 2,437
  • 3
  • 21
  • 31
  • You may be correct in terms of bulk writing to a databse, but isn't this logging? Logging is about "writing down" events; This recording should happen as soon as it can. So how do you propose to establish low water marks in your overridden method? How will you determine when it is best to bulk write the loggingevents? What if the app crashes while you still have a full array of event that you are waiting to write? I think the log4net guys have probably done research on this. Pop over and ask them... – Marc Lyon Sep 27 '16 at 12:50
  • If performance is really an issue, are you [logging too much](https://blog.codinghorror.com/the-problem-with-logging/)? – stuartd Sep 28 '16 at 21:00

1 Answers1

0

You can make a class like:

public class MyAdoNetAppender : AdoNetAppender
{
    override protected void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
    {
        (... implementation goes here)
    }
}

You can use the class in config like (MyDll is your dll name, and make sure you have the namespace correct):

 <appender name="A1" type="MyAdoNetAppender,MyDll">
Peter
  • 27,590
  • 8
  • 64
  • 84