Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/log4net/Appender/AdoNetAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,23 +557,26 @@ protected virtual void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
try
{
// prepare the command, which is significantly faster
dbCmd.Prepare();
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)
{
// clear parameters that have been set
dbCmd.Parameters.Clear();

// No need to clear dbCmd.Parameters, just use existing.
// Set the parameter values
foreach (AdoNetAppenderParameter param in m_parameters)
{
param.Prepare(dbCmd);
param.FormatValue(dbCmd, e);
}

Expand Down Expand Up @@ -606,6 +609,21 @@ protected virtual void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
}
}

/// <summary>
/// Prepare entire database command object to be executed.
/// </summary>
/// <param name="dbCmd">The command to prepare.</param>
protected virtual void Prepare(IDbCommand dbCmd)
{
// npgsql require parameters to prepare command
foreach (AdoNetAppenderParameter parameter in m_parameters)
{
parameter.Prepare(dbCmd);
}

dbCmd.Prepare();
}

/// <summary>
/// Formats the log message into database statement text.
/// </summary>
Expand Down