|
Raghue, No that’s the original code of the
SendBuffer, the one I didn’t get to work, so I wrote a modified
version that I posted earlier, I enclose my previous mail below; in case it
got lost somewhere. Regards Georg http://www.l4ndash.com Log4Net Dashboard /
Log4Net Viewer 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. 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.
InitializeDatabaseConnection();
InitializeDatabaseCommand(); } int NoOfReTry; bool Suce if (m_reconnectOnError) { NoOfReTry
= 2; } else { NoOfReTry
= 1; } for (int
iTryNo = 1; iTryNo <= NoOfReTry && Suce { 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();
Suce
}
catch (Exception ex)
{
// rollback the transaction
if (dbTran != null)
{
try
{
dbTran.Rollback();
}
catch (Exception)
{
// 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);
Suce
}
} } catch (Exception ex) {
Suce } } } |
- Database Appender Ismay, Greg \(CALBRIS\)
- RE: Database A... Nicko Cadell
- RE: Database A... Simon Wallis
- RE: Databas... Georg Jansen
- RE: Database Ap... Ron Grabowski
- RE: Database Ap... Bejugam, Raghavendra \(GE Commercial Finance, NonGE\)
- RE: Databas... Georg Jansen
- RE: Database Ap... Bejugam, Raghavendra \(GE Commercial Finance, NonGE\)
- RE: Databas... Georg Jansen
- RE: Database Ap... Simon Wallis
- RE: Databas... Georg Jansen
