简体   繁体   中英

Logging to SQL Server in bulks using log4net

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)

AdoNetAppender.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM