protected override void SendBuffer()

in src/log4net/Appender/AdoNetAppender.cs [395:441]


  protected override void SendBuffer(LoggingEvent[] events)
  {
    if (ReconnectOnError && (Connection is null || Connection.State != ConnectionState.Open))
    {
      LogLog.Debug(_declaringType, $"Attempting to reconnect to database. Current Connection State: {((Connection is null) ? SystemInfo.NullText : Connection.State.ToString())}");

      InitializeDatabaseConnection();
    }

    // Check that the connection exists and is open
    if (Connection is not null && Connection.State == ConnectionState.Open)
    {
      if (UseTransactions)
      {
        // Create transaction
        // NJC - Do this on 2 lines because it can confuse the debugger
        using IDbTransaction dbTran = Connection.BeginTransaction();
        try
        {
          SendBuffer(dbTran, events);

          // commit transaction
          dbTran.Commit();
        }
        catch (Exception ex) when (!ex.IsFatal())
        {
          // rollback the transaction
          try
          {
            dbTran.Rollback();
          }
          catch (Exception inner) when (!inner.IsFatal())
          {
            // Ignore exception
          }

          // Can't insert into the database. That's a bad thing
          ErrorHandler.Error("Exception while writing to database", ex);
        }
      }
      else
      {
        // Send without transaction
        SendBuffer(null, events);
      }
    }
  }