Search code examples
c#log4netlog4net-configurationlog4net-appender

Log4net adoNetAppender dosent insert logging event in bulk


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.


Solution

  • 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">