You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2020/12/07 14:51:47 UTC

[GitHub] [logging-log4net] NicholasNoise opened a new pull request #71: Fix AdoNetAppender using npgsql

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:
users@infra.apache.org



[GitHub] [logging-log4net] fluffynuts commented on a change in pull request #71: Fix AdoNetAppender using npgsql

Posted by GitBox <gi...@apache.org>.
fluffynuts commented on a change in pull request #71:
URL: https://github.com/apache/logging-log4net/pull/71#discussion_r538061769



##########
File path: src/log4net/Appender/AdoNetAppender.cs
##########
@@ -553,8 +553,17 @@ protected virtual void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
 					{
 						dbCmd.Transaction = dbTran;
 					}
-					// prepare the command, which is significantly faster
-					dbCmd.Prepare();
+
+					try
+					{
+						// prepare the command, which is significantly faster
+						dbCmd.Prepare();
+					}
+					catch (Exception)
+					{
+						// Ignore exception

Review comment:
       whilst I'd like to track down the _why_ of this instead of skipping over it, I think that may take some time -- I don't even have pgsql installed on any of my machines. As far as I understand, the only side-effect here is that the command might run a little slower, so I'd say, let's put in this workaround, but please put in a comment explaining why, eg `// ignore prepare exceptions as they can happen without affecting actual logging, eg on pgsql`. Thoughts?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [logging-log4net] NicholasNoise commented on pull request #71: Fix AdoNetAppender using npgsql

Posted by GitBox <gi...@apache.org>.
NicholasNoise commented on pull request #71:
URL: https://github.com/apache/logging-log4net/pull/71#issuecomment-739967799


   @fluffynuts
   At a look please.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [logging-log4net] NicholasNoise commented on a change in pull request #71: Fix AdoNetAppender using npgsql

Posted by GitBox <gi...@apache.org>.
NicholasNoise commented on a change in pull request #71:
URL: https://github.com/apache/logging-log4net/pull/71#discussion_r538174819



##########
File path: src/log4net/Appender/AdoNetAppender.cs
##########
@@ -553,8 +553,17 @@ protected virtual void SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
 					{
 						dbCmd.Transaction = dbTran;
 					}
-					// prepare the command, which is significantly faster
-					dbCmd.Prepare();
+
+					try
+					{
+						// prepare the command, which is significantly faster
+						dbCmd.Prepare();
+					}
+					catch (Exception)
+					{
+						// Ignore exception

Review comment:
       I've investigated it. The simple _why_ is to prepare a valid command instead of invalid one without parameters and values.
   Also tracked down to inner command cache, so it is not necessary to prepare command.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [logging-log4net] fluffynuts merged pull request #71: Fix AdoNetAppender using npgsql

Posted by GitBox <gi...@apache.org>.
fluffynuts merged pull request #71:
URL: https://github.com/apache/logging-log4net/pull/71


   


----------------------------------------------------------------
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:
users@infra.apache.org