NicholasNoise opened a new pull request #71:
URL: https://github.com/apache/logging-log4net/pull/71


   Using npgsql on netfx and mono I've encountered this error on an applicaiton 
startup:
   ```
   log4net:ERROR [CustomAdoNetAppender] ErrorCode: GenericFailure. Exception 
while writing to database
   Npgsql.PostgresException (0x80004005): 42601: syntax error at or near ":"
      at Npgsql.NpgsqlConnector.DoReadMessage(Boolean async, DataRowLoadingMode 
dataRowLoadingMode, Boolean readingNotifications, Boolean isPrependedMessage)
      at Npgsql.NpgsqlConnector.ReadMessage(Boolean async, DataRowLoadingMode 
dataRowLoadingMode, Boolean readingNotifications)
      at Npgsql.NpgsqlConnector.ReadMessage(Boolean async, DataRowLoadingMode 
dataRowLoadingMode, Boolean readingNotifications)
      at Npgsql.NpgsqlConnector.ReadExpecting[T](Boolean async)
      at Npgsql.NpgsqlCommand.Prepare()
      at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, 
LoggingEvent[] events)
      at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
   ```
   The error prevents to write **only** very first logging event, because 
Npgsql fails to prepare command with no parameters (at a moment). So it is not 
a problem in general, but disturbing.
   
   I think my _fix_ is not that good but does a trick. An alternative is to 
disable `dbCmd.Prepare();` if it fails once:
   ```
                                        if (m_doCommandPrepare)
                                        {
                                                try
                                                {
                                                        // prepare the command, 
which is significantly faster
                                                        dbCmd.Prepare();
                                                }
                                                catch (Exception)
                                                {
                                                        m_doCommandPrepare = 
false;
                                                }
                                        }
   ...
                private bool m_doCommandPrepare = true;
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to