in src/log4net/Appender/AdoNetAppender.cs [539:610]
protected virtual void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
{
// string.IsNotNullOrWhiteSpace() does not exist in ancient .NET frameworks
if (CommandText != null && CommandText.Trim() != "")
{
using (IDbCommand dbCmd = Connection.CreateCommand())
{
// Set the command string
dbCmd.CommandText = CommandText;
// Set the command type
dbCmd.CommandType = CommandType;
// Send buffer using the prepared command object
if (dbTran != null)
{
dbCmd.Transaction = dbTran;
}
try
{
// prepare the command, which is significantly faster
Prepare(dbCmd);
}
catch (Exception)
{
if (dbTran != null)
{
// rethrow exception in transaction mode, cuz now transaction is in failed state
throw;
}
// ignore prepare exceptions as they can happen without affecting actual logging, eg on npgsql
}
// run for all events
foreach (LoggingEvent e in events)
{
// No need to clear dbCmd.Parameters, just use existing.
// Set the parameter values
foreach (AdoNetAppenderParameter param in m_parameters)
{
param.FormatValue(dbCmd, e);
}
// Execute the query
dbCmd.ExecuteNonQuery();
}
}
}
else
{
// create a new command
using (IDbCommand dbCmd = Connection.CreateCommand())
{
if (dbTran != null)
{
dbCmd.Transaction = dbTran;
}
// run for all events
foreach (LoggingEvent e in events)
{
// Get the command text from the Layout
string logStatement = GetLogStatement(e);
LogLog.Debug(declaringType, "LogStatement [" + logStatement + "]");
dbCmd.CommandText = logStatement;
dbCmd.ExecuteNonQuery();
}
}
}
}