log4net ADO Stored Procedure
I am trying to call an existing Stored Procedure but can't get it to log. Seems to be parameter type conversion problem, but I can't figure it out.
Error on build is:
log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [conversionPattern] to set object on [log4net.Layout.RawPropertyLayout]
web.config is:
<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
<bufferSize value="1" />
<threshold value="ALL"/>
<param name="ConnectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<param name="ConnectionString" value="Data Source=central-db.canterbury.ac.uk\devel;Initial Catalog=SourceDB;Persist Security Info=True;/>
<param name="UseTransactions" value="False" />
<commandText value="dbo.usperrLogError" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@ApplicationId"/>
<dbType value="String"/>
<size value="2" />
<layout type="log4net.Layout.RawPropertyLayout">
<key value="EventGuid" />
<conversionPattern value="%property{APP-ID}"/>
</layout>
</parameter>
//
<parameter>
<parameterName value="@EventGuid"/>
<dbType value="String"/>
<size value="50" />
<layout type="log4net.Layout.RawPropertyLayout">
<key value="EventGuid" />
<conversionPattern value="%property{GUID}"/>
</layout>
</parameter>
Am setting Properties like this:
log4net.ThreadContext.Properties["GUID"] = eventGuid.ToString();
Following the log4net debug error there is an additional error here:
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
log4net:ERROR [AdoNetAppender] Failed in DoAppend
System.ArgumentNullException: Key cannot be null.
Parameter name: key
at System.Collections.Hashtable.get_Item(Object key)
at log4net.Util.PropertiesDictionary.get_Item(String key) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Util\PropertiesDictionary.cs:line 114
at log4net.Core.LoggingEvent.LookupProperty(String key) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Core\LoggingEvent.cs:line 1404
at log4net.Layout.RawPropertyLayout.Format(LoggingEvent loggingEvent) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Layout\RawPropertyLayout.cs:line 84
at log4net.Appender.AdoNetAppenderParameter.FormatValue(IDbCommand command, LoggingEvent loggingEvent) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Appender\AdoNetAppender.cs:line 1117
at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Appender\AdoNetAppender.cs:line 560
at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Appender\AdoNetAppender.cs:line 501
at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent) in c:\work\svn_root\apache\log4net\tags\log4net开发者_Python百科-1.2.10-rc2\build\package\log4net-1.2.10\src\Appender\BufferingAppenderSkeleton.cs:line 463
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent) in c:\work\svn_root\apache\log4net\tags\log4net-1.2.10-rc2\build\package\log4net-1.2.10\src\Appender\AppenderSkeleton.cs:line 316
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
log4net:ERROR [AdoNetAppender] Failed in DoAppend
System.ArgumentNullException: Key cannot be null.
Clearly I am not using RawPropertyLayout
correctly but can't find good examples!
I do something like you, but I use the log4net.Layout.PatternLayout
like this:
<parameter>
<parameterName value="@ProjectParam1"/>
<dbType value="String"/>
<size value="254" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{OrderNumber}" />
</layout>
</parameter>
If I understand the log4net.Layout.RawPropertyLayout
correctly, you have to use it as follows:
<parameterName value="@EventGuid"/>
<dbType value="String"/>
<size value="50" />
<layout type="log4net.Layout.RawPropertyLayout">
<param name="Key" value="GUID" />
</layout>
</parameter>
精彩评论