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

AdoNetAppender does not support inserting NULL into columns

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.9
    • Fix Version/s: 1.2.10
    • Component/s: Appenders
    • Labels:
      None

      Description

      The AdoNetAppender does not support inserting NULL values into columns.

      If a column allows NULL values then the AdoNetAppender should allow NULL values to be inserted. For most value types this means using the DBNull value for the parameter. The AdoNetAppenderParameter should convert CLI null values into DBNull values before setting the parameter value.

        Activity

        Hide
        nicko Nicko Cadell added a comment -

        Fix to AdoNetAppenderParameter FormatValue to convert the null runtime value to DBNull value.

        Show
        nicko Nicko Cadell added a comment - Fix to AdoNetAppenderParameter FormatValue to convert the null runtime value to DBNull value.
        Hide
        secretagent Greg Peterson added a comment - - edited

        The PatternLayout uses SystemInfo.NullText which returns a string "(null)" not the null value. If you use a custom property and set it to null, you will not have the parameter set to DBNull.

        The PatternConverter.WriteObject(TextWriter writer, ILoggerRepository repository, object value) calls repository.RendererMap.FindAndRender(value, writer);

        which in turn, sets the value to "(null)" because the object value is null.

        if (obj == null)

        { writer.Write(SystemInfo.NullText); }

        else
        {
        .....

        Maybe it should be

        if (formattedValue == null || formattedValue.ToString() == SystemInfo.NullText)

        { formattedValue = DBNull.Value; }
        Show
        secretagent Greg Peterson added a comment - - edited The PatternLayout uses SystemInfo.NullText which returns a string "(null)" not the null value. If you use a custom property and set it to null, you will not have the parameter set to DBNull. The PatternConverter.WriteObject(TextWriter writer, ILoggerRepository repository, object value) calls repository.RendererMap.FindAndRender(value, writer); which in turn, sets the value to "(null)" because the object value is null. if (obj == null) { writer.Write(SystemInfo.NullText); } else { ..... Maybe it should be if (formattedValue == null || formattedValue.ToString() == SystemInfo.NullText) { formattedValue = DBNull.Value; }
        Hide
        ron Ron Grabowski added a comment -

        Its generally a good idea to post general questions about log4net to the mailing lists first. This issue has been closed for almost 3 years.

        Are you using a RawPropertyLayout layout?

        <parameter>
        <parameterName value="@productId" />
        <dbType value="String" />
        <size value="50" />
        <layout type=" log4net.Layout.RawPropertyLayout">
        <key value="ProductId" />
        </layout>
        </parameter>

        log.Debug("Message");
        // snip
        IDbDataParameter param = (IDbDataParameter)command.Parameters["@productId"];
        Assert.AreEqual(DBNull.Value, param.Value);

        Show
        ron Ron Grabowski added a comment - Its generally a good idea to post general questions about log4net to the mailing lists first. This issue has been closed for almost 3 years. Are you using a RawPropertyLayout layout? <parameter> <parameterName value="@productId" /> <dbType value="String" /> <size value="50" /> <layout type=" log4net.Layout.RawPropertyLayout"> <key value="ProductId" /> </layout> </parameter> log.Debug("Message"); // snip IDbDataParameter param = (IDbDataParameter)command.Parameters ["@productId"] ; Assert.AreEqual(DBNull.Value, param.Value);

          People

          • Assignee:
            nicko Nicko Cadell
            Reporter:
            nicko Nicko Cadell
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development