[ 
http://issues.apache.org/jira/browse/LOG4NET-89?page=comments#action_12426860 ] 
            
Haacked commented on LOG4NET-89:
--------------------------------

Ron, I walked through the debugger and got a null reference exception in 
AdoNetAppender.cs in the method FormatValue on the following line:

        object formattedValue = Layout.Format(loggingEvent);

Turns out that Layout (m_layout) is null when I use RawPatternLayout.

I also tried using this snippet (found here: 
http://marc2.theaimsgroup.com/?l=log4net-user&m=111450072902528&w=2)

<parameter>
  <parameterName value="@spid" />
  <dbType value="Int32" />

  <layout type="log4net.Layout.RawPropertyLayout">
    <key value="spid" />
  </layout>
</parameter

But that didn't work.  Seems like it should be easy enough to fix. Simply check 
if Layout is null and if so, set formattedValue to null. That would then solve 
this problem and allow null values for int properties.  Should I send a patch 
or is there something else wrong with that?

> Still A Problem Inserting Null Value For Int32 Values
> -----------------------------------------------------
>
>                 Key: LOG4NET-89
>                 URL: http://issues.apache.org/jira/browse/LOG4NET-89
>             Project: Log4net
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 1.2.10
>         Environment: Windows XP .NET 2.0
>            Reporter: Haacked
>         Attachments: AdoNetAppender.txt, AdoNetAppenderException.txt, 
> subtext_AddLogEntry.txt
>
>
> I know a fix for this has been issued, but I think there is still a bug. I 
> have a stored procedure I use with my AdoNetAppender in Subtext 
> (http://subtextproject.com/ source code in SVN at 
> https://svn.sourceforge.net/svnroot/subtext/). 
> The stored proc has an Int32 parameter (@BlogId) that may be null in certain 
> situations).  When I trace through the Log4Net code, I notice that it obtains 
> a formatted value within AdoNetAppender.cs line 1167.  It then compares that 
> value to null, and if it is null, sets the formattedValue to DBNull.Value.
>     object formattedValue = Layout.Format(loggingEvent);
>     // If the value is null then convert to a DBNull
>     if (formattedValue == null)
>     {
>         formattedValue = DBNull.Value;
>     }
>     param.Value = formattedValue;
> However, when I check the value of formattedValue, it is the string "(null)" 
> and not a null reference.  I traced the code all the way to the FindAndRender 
> method of RenderMap.cs line 113 which begins like so:
>     if (obj == null)
>     {
>         writer.Write(SystemInfo.NullText);
>     }
> I don't know this code well enough to know whether the proper patch is to 
> update AdoNetAppender.cs line 1167 to be: 
>     if (formattedValue == null || formattedValue.ToString() == 
> SystemInfo.NullText)
> Or if the proper fix is elsewhere.
> ATTACHMENTS:
> subtext_AddLogEntry.txt - The stored proc I am trying to call.
> AdoNetAppender.txt - The AdoNetAppender configuration in my web.config.
> AdoNetAppenderException.txt - The exception I get.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to