I'm using log4net to log messages to a SQL Server database using the AdoNetAppender
. I need to insert the logs in bulks. I've tried using the batchSize
property of the appender, but as far as I can tell the result is something like:
conn.Open();
for (int i = 0; i < count; i++)
{
comm.ExecuteNonReader();
}
conn.Close();
And this eventually translates to a bunch of Inserts. So if my batch size is for instance 500, then there will be 500 consecutive inserts.
My goal is for the bulks to be inserted in 1 insert statement. Like .NET's SqlBulkCopy
.
Is it possible to achieve this result with log4net? Or do I have to implement my own custom appender to do so?
You have to write your own custom appender because log4net does not do this out of the box. You can just inherrit from the AdoNetAppender and override the virtual protected void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)