Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-495

Error when BufferSize is >1, parameter already defined

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.15
    • Fix Version/s: 1.2.15
    • Component/s: Appenders
    • Labels:
      None
    • Environment:
      Windows 7

      Description

      Downloaded the subject revision 1714197 in order to get the ADONetAppender_SqlServer appender to work as this revision corrected a problem. The appender began to work. However if the BufferSize was increased to >1 an error was reported that the parameter @log_date was already defined.

      The error appears to be in SendBuffer. Because the IDbCommand dbCmd is being reused inside the foreach (LoggingEvent e in Events), each time the param.Prepare(dbCmd) is called for the same appender it will attempt to add a parameter that has already been added.

      My local solution was to clear the commands parameter list prior to adding the preparing the paramters:
      foreach (LoggingEvent e in events)
      {
      dbCmd.Parameters.Clear(); //****added this line****

      // Set the parameter values
      foreach (AdoNetAppenderParameter param in m_parameters)

      { param.Prepare(dbCmd); param.FormatValue(dbCmd, e); }

      // Execute the query
      dbCmd.ExecuteNonQuery();
      }

        Activity

        Hide
        nachbarslumpi Dominik Psenner added a comment -

        Thanks for testing the appender. Your report is sound and I'll fix it as you suggested. I'll also try to write down a test so that we can be sure this usecase is covered by the unittests.

        Show
        nachbarslumpi Dominik Psenner added a comment - Thanks for testing the appender. Your report is sound and I'll fix it as you suggested. I'll also try to write down a test so that we can be sure this usecase is covered by the unittests.
        Hide
        nachbarslumpi Dominik Psenner added a comment -

        Fix committed as svn revision 1716909.

        Show
        nachbarslumpi Dominik Psenner added a comment - Fix committed as svn revision 1716909.
        Hide
        nachbarslumpi Dominik Psenner added a comment - - edited

        While writing a test I noticed that your solution does not break existing tests and therefore I adjusted the patch. Should be fixed now and I'm resolving the issue. It would be nice if you could run log4net from source and confirm that the latest trunk fixes your issue. We can then close the issue.

        Show
        nachbarslumpi Dominik Psenner added a comment - - edited While writing a test I noticed that your solution does not break existing tests and therefore I adjusted the patch. Should be fixed now and I'm resolving the issue. It would be nice if you could run log4net from source and confirm that the latest trunk fixes your issue. We can then close the issue.
        Hide
        rickburge@comcast.net Rick Burge added a comment -

        Downloaded and tested this morning and all appears to work. Thx.

        Show
        rickburge@comcast.net Rick Burge added a comment - Downloaded and tested this morning and all appears to work. Thx.
        Hide
        nachbarslumpi Dominik Psenner added a comment -

        Great, thanks.

        Show
        nachbarslumpi Dominik Psenner added a comment - Great, thanks.

          People

          • Assignee:
            nachbarslumpi Dominik Psenner
            Reporter:
            rickburge@comcast.net Rick Burge
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development