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
Repository Revision Date User Message
ASF #312281 Tue May 03 10:48:13 UTC 2005 nicko Fix for LOG4NET-28. AdoNetAppender does not support inserting NULL into columns
Files Changed
MODIFY /logging/log4net/trunk/src/Appender/AdoNetAppender.cs

Nicko Cadell added a comment - 03/May/05 07:52 PM
Fix to AdoNetAppenderParameter FormatValue to convert the null runtime value to DBNull value.

Nicko Cadell made changes - 03/May/05 07:52 PM
Field Original Value New Value
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
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);

Repository Revision Date User Message
ASF #617264 Thu Jan 31 22:32:38 UTC 2008 rgrabowski Test for LOG4NET-28 demonstrating how to insert NULL values using both an xml configuration and progmatic configuration.
Files Changed
MODIFY /logging/log4net/trunk/tests/src/Appender/AdoNetAppenderTest.cs