Log4net
  1. Log4net
  2. LOG4NET-202

AdoNetAppenderParameter.Size Property is not optional

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.10, 1.2.11
    • Fix Version/s: 1.2.12
    • Component/s: Documentation
    • Labels:
      None
    • Environment:
      Windows Server 2008, .NET 3.5 SP1, SQL Server 2008

      Description

      The AdoNetAppenderParameter.Size page (http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppenderParameter.Size.html) says "This property is optional. If not specified the ADO.NET provider will attempt to infer the size from the value."

      However, I just got the following exception in the log4net internal debug trace, with the following parameter (maps to a VARCHAR(MAX)):

      <parameter>
      <parameterName value="@exception" />
      <dbType value="String" />
      <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>

      log4net:ERROR [AdoNetAppender] Could not prepare database command [INSERT INTO ....]
      System.InvalidOperationException: SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.
      at System.Data.SqlClient.SqlParameter.Prepare(SqlCommand cmd)
      at System.Data.SqlClient.SqlCommand.Prepare()
      at log4net.Appender.AdoNetAppender.InitializeDatabaseCommand()

      This would suggest the Size parameter cannot be null.

        Activity

        Hide
        Ron Grabowski added a comment -

        Have you tried using SqlDbType.Text and/or a size of -1?

        http://stackoverflow.com/questions/596257/what-sqldbtype-maps-to-varcharmax

        Show
        Ron Grabowski added a comment - Have you tried using SqlDbType.Text and/or a size of -1? http://stackoverflow.com/questions/596257/what-sqldbtype-maps-to-varcharmax
        Hide
        Stefan Bodewig added a comment -

        I have changed the documentation in svn to recommend using -1 explicitly but it would if anybody could confirm this actually works before I close the issue (and update the site).

        Show
        Stefan Bodewig added a comment - I have changed the documentation in svn to recommend using -1 explicitly but it would if anybody could confirm this actually works before I close the issue (and update the site).
        Hide
        Meltan added a comment -

        Setting size to -1 works for me with version 1.2.9.
        I think you can close this issue.

        Show
        Meltan added a comment - Setting size to -1 works for me with version 1.2.9. I think you can close this issue.
        Hide
        Richard Dingwall added a comment - - edited

        Meltan yes I know there is a workaround. That is not the issue. The purpose of this JIRA is to fix the documentation which still says (more than three and a half years since I raised this issue!), "This property is optional": http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppenderParameter.Size.html.

        Either:

        1. This line needs to be removed from the documentation and a note added about setting it to -1 (Stefan may have already done this), OR
        2. If dbType is String and no size is specified, log4net should implicitly set size = -1 under the covers. That way it really will be optional and the documentation will be correct.

        Show
        Richard Dingwall added a comment - - edited Meltan yes I know there is a workaround. That is not the issue. The purpose of this JIRA is to fix the documentation which still says (more than three and a half years since I raised this issue!), "This property is optional": http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppenderParameter.Size.html . Either: 1. This line needs to be removed from the documentation and a note added about setting it to -1 (Stefan may have already done this), OR 2. If dbType is String and no size is specified, log4net should implicitly set size = -1 under the covers. That way it really will be optional and the documentation will be correct.
        Hide
        Dominik Psenner added a comment -

        Fixed as of revision 1198796. Please reopen the issue if that is not the case.

        Show
        Dominik Psenner added a comment - Fixed as of revision 1198796. Please reopen the issue if that is not the case.

          People

          • Assignee:
            Unassigned
            Reporter:
            Richard Dingwall
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 0.5h
              0.5h
              Remaining:
              Remaining Estimate - 0.5h
              0.5h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development