I think a more generalized approach would be to mimic NLog's RetryTargetWrapper wrapper to allow any Appender to be retried:
<appender name="RetryAdoNetAppender" type="RetryAppender"> <retryCount value="3" /> <retryMillisecondDelay value="100" /> <appender-ref ref="AdoNetAppender" /> </appender> --- Georg Jansen <[EMAIL PROTECTED]> wrote: > > > > > I did some modifications to the SendBuffer method of AdoNetAppender, > and it > seems to work. I tested it -- starting and stopping SQLServer between > log > calls. > > The modified source is based on the 1.2.9 source where the config > parameter > reconnectonerror is available. > > > > I have kept the original "retry code" but it doesn't seems like it is > working, the m_dbConnection.State is not (at least during my test) > updated > if a connection is dropped from the server. > > > > > > Regards > > Georg > > http://www.l4ndash.com <http://www.l4ndash.com/> Log4Net Dashboard / > Log4Net Viewer > > > > > > > > override protected void SendBuffer(LoggingEvent[] events) > > { > > if (m_reconnectOnError && (m_dbConnection == null || > m_dbConnection.State > != ConnectionState.Open)) > > { > > LogLog.Debug("AdoNetAppender: Attempting to reconnect to > database. > Current Connection State: " + > ((m_dbConnection==null)?"<null>":m_dbConnection.State.ToString()) ); > > > > InitializeDatabaseConnection(); > > InitializeDatabaseCommand(); > > } > > > > int NoOfReTry; > > bool Sucess = false; > > > > if (m_reconnectOnError) > > { > > NoOfReTry = 2; > > } > > else > > { > > NoOfReTry = 1; > > > > } > > > > for (int iTryNo = 1; iTryNo <= NoOfReTry && Sucess == false; > iTryNo++) > > { > > try > > { > > if (iTryNo > 1) // second time? --> try to reconnect > > { > > while (iTryNo <= NoOfReTry) > > { > > LogLog.Debug("AdoNetAppender: Attempting to > reconnect to > database"); > > > > InitializeDatabaseConnection(); > > if (m_dbConnection != null && > m_dbConnection.State == > ConnectionState.Open) > > break; > > > > iTryNo++; > > } > > > > if (m_dbConnection == null || m_dbConnection.State != > ConnectionState.Open) > > { > > LogLog.Error("Giving up database reconect after > trying: > " + NoOfReTry.ToString() + " times"); > > return; > > } > > > > InitializeDatabaseCommand(); > > } > > > > // Check that the connection exists and is open > > if (m_dbConnection != null && m_dbConnection.State == > ConnectionState.Open) > > { > > if (m_useTransactions) > > { > > // Create transaction > > // NJC - Do this on 2 lines because it can > confuse the > debugger > > IDbTransaction dbTran = null; > > try > > { > > dbTran = m_dbConnection.BeginTransaction(); > > > > SendBuffer(dbTran, events); > > > > // commit transaction > > dbTran.Commit(); > > Sucess = true; > > } > > catch (Exception ex) > > { > > // rollback the transaction > > if (dbTran != null) > > { > > try > > { > === message truncated ===
