title: Make log4net reconnect to database after database down
body: <p>I use Log4Net Windows Service saving the logs in the database.
  I am getting the following error:</p>
  
  <pre><code>log4net:ERROR [CustomAdoNetAppender] ErrorCode: GenericFailure. Failed in DoAppend
  System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---&gt; System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
     at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
     at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
     at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
     at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
     at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte&amp; value)
     at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)
     at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
     at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
     at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
     at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
     at System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName, Boolean shouldReconnect)
     at System.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso, String transactionName)
     at System.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
     at System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()
     at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
     at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent)
     at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
  ClientConnectionId:a0b7de5e-2689-407b-b0da-5ebc733c0986
  log4net: Attempting to reconnect to database. Current Connection State: Closed
  log4net: Attempting to reconnect to database. Current Connection State: (null)
  log4net: Attempting to reconnect to database. Current Connection State: (null)
  log4net: Attempting to reconnect to database. Current Connection State: (null)
  log4net: Attempting to reconnect to database. Current Connection State: (null)
  </code></pre>
  
  <p>My configuration Lo4Net in service windows is:</p>
  
  <pre><code>&lt;log4net&gt;
      &lt;appender name="AdoNetAppender" type="App.Uteis.CustomAdoNetAppender"&gt;
        &lt;bufferSize value="1" /&gt;
        &lt;reconnectonerror value="true" /&gt;
        &lt;connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
        &lt;commandText value="INSERT INTO Log_Aplicacao ([Dt_Log],[Ds_Thread],[Ds_Nivel],[Ds_Servidor],[Ds_Aplicacao],[Ds_Login],[Ds_Log],[Ds_Mensagem],[Ds_Erro]) VALUES (@log_date, @thread, @log_level, @host_name,'AppMaster', @user_name, @logger, @message, @exception)" /&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@log_date" /&gt;
          &lt;dbType value="DateTime" /&gt;
          &lt;layout type="log4net.Layout.RawTimeStampLayout" /&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@thread" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="255" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%thread" /&gt;
          &lt;/layout&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@log_level" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="50" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%level" /&gt;
          &lt;/layout&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@host_name" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="200" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%property{log4net:HostName}" /&gt;
          &lt;/layout&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@user_name" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="150" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%username" /&gt;
          &lt;/layout&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@logger" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="2000" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%logger" /&gt;
          &lt;/layout&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@message" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="8000" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
            &lt;conversionPattern value="%message" /&gt;
          &lt;/layout&gt;
        &lt;/parameter&gt;
        &lt;parameter&gt;
          &lt;parameterName value="@exception" /&gt;
          &lt;dbType value="String" /&gt;
          &lt;size value="8000" /&gt;
          &lt;layout type="log4net.Layout.ExceptionLayout" /&gt;
        &lt;/parameter&gt;
      &lt;/appender&gt;
      &lt;root&gt;
        &lt;level value="ALL" /&gt;
        &lt;appender-ref ref="AdoNetAppender" /&gt;
      &lt;/root&gt;
    &lt;/log4net&gt;
  </code></pre>
  
  <p>The configuration of my <strong>CustomAdoNetAppender</strong> class is:</p>
  
  <pre><code>namespace AprovadorCartao.Uteis
  {
      public class CustomAdoNetAppender : AdoNetAppender
      {
          public static RegistryKey _configRegistry = Registry.LocalMachine.OpenSubKey("Software\\Conexao");
  
          public override void ActivateOptions()
          {
              PopulateConnectionString();
              base.ActivateOptions();
          }
  
          private void PopulateConnectionString()
          {
              ConnectionString = ConnectionString;
          }
  
          public new string ConnectionString
          {
              get { return base.ConnectionString; }
              set
              {
                  base.ConnectionString = (string)_configRegistry.GetValue("Conexao") + ";Connect Timeout=1;";
              }
          }
      }
  }
  </code></pre>
  
  <p>The Log4Net only back to normal (save in the database) after I restart the service.</p>
  
  <p>Every time there is a mistake with my database, the Log4Net to save data in the database. Is there any configuration in which the Log4Net again automatically log in Windows Service?</p>