[
http://issues.apache.org/jira/browse/LOG4NET-89?page=comments#action_12427160 ]
Nicko Cadell commented on LOG4NET-89:
-------------------------------------
The standard layouts always return a non-null string. The 'raw' layouts return
an object, which will be null if the value is null of missing. You will never
get a null value back from the PatternLayout.
If m_layout is null then the layout has not been correctly configured. In this
case it is because there isn't a RawPaternLayout type. m_layout is used to get
the value from the event, if it is missing then there is no way to get the
value at all (null or otherwise) so you definitely need m_layout to be set.
You should be able to use the RawPropertyLayout to get the BlogId value,
including setting it to null if it is not defined. The following snippet of
AdoNetAppender configuration works for me:
<parameter>
<parameterName value="@BlogId" />
<dbType value="Int32" />
<layout type="log4net.Layout.RawPropertyLayout">
<key value="BlogId" />
</layout>
</parameter>
As this is a configuration question I am going to go ahead and close this
issue. If you have any further questions please use the log4net-user list
before raising an issue.
> 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