Issue Details (XML | Word | Printable)

Key: LOG4NET-28
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Nicko Cadell
Reporter: Nicko Cadell
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Log4net

AdoNetAppender does not support inserting NULL into columns

Created: 03/May/05 07:20 PM   Updated: 31/Jan/08 10:15 PM
Return to search
Component/s: Appenders
Affects Version/s: 1.2.9
Fix Version/s: 1.2.10

Time Tracking:
Not Specified

Resolution Date: 03/May/05 07:52 PM


 Description  « Hide
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.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Nicko Cadell added a comment - 03/May/05 07:52 PM
Fix to AdoNetAppenderParameter FormatValue to convert the null runtime value to DBNull value.

Greg Peterson added a comment - 31/Jan/08 07:33 PM - 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;
}

Ron Grabowski added a comment - 31/Jan/08 10:15 PM
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);