如何在 log4net ADONetAppender 中使用存储过程?
我正在使用 ADONetAppender(尝试)通过存储过程记录数据(以便我可以将逻辑注入到日志记录例程中)。
下面列出了我的配置设置。 有人能告诉我我做错了什么吗?
<appender name="ADONetAppender_SqlServer" 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="<MyConnectionString>" />
<param name="UseTransactions" value="False" />
<commandText value="dbo.LogDetail_via_Log4Net" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@AppLogID"/>
<dbType value="String"/>
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{LoggingSessionId}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CreateUser"/>
<dbType value="String"/>
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{HttpUser}" />
</layout>
</parameter>
<parameter>
<parameterName value="@Message"/>
<dbType value="String"/>
<size value="8000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@LogLevel"/>
<dbType value="String"/>
<size value="50"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
</appender>
I am using the ADONetAppender to (try) to log data via a stored procedure (so that I may inject logic into the logging routine).
My configuration settings are listed below. Can anybody tell what I'm doing wrong?
<appender name="ADONetAppender_SqlServer" 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="<MyConnectionString>" />
<param name="UseTransactions" value="False" />
<commandText value="dbo.LogDetail_via_Log4Net" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@AppLogID"/>
<dbType value="String"/>
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{LoggingSessionId}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CreateUser"/>
<dbType value="String"/>
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{HttpUser}" />
</layout>
</parameter>
<parameter>
<parameterName value="@Message"/>
<dbType value="String"/>
<size value="8000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@LogLevel"/>
<dbType value="String"/>
<size value="50"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
</appender>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用“AnsiString”作为 varchar 的 dbType。 nvarchar 的“字符串”。
http://msdn.microsoft .com/en-us/library/system.data.dbtype%28v=VS.90%29.aspx
Use "AnsiString" as dbType for varchar. "String" for nvarchar.
http://msdn.microsoft.com/en-us/library/system.data.dbtype%28v=VS.90%29.aspx
感谢一位警惕的 DBA,我们解决了这个问题。
请注意“@Message”参数的大小。 log4net 正在猜测如何转换类型并(我认为)将其转换为 nvarchar,即使该列是 varchar。 这是一件大事,因为 nvarchar 的最大大小为 4000,而 varchar 的最大大小为 8000。DBA
看到了此知识库文章中所述的错误:http://support.microsoft.com/kb/827366
我将大小更改为 4000,一切顺利。
希望这会帮助其他人避免同样的问题。
干杯!
Thanks to a vigilant DBA, we have solved the problem.
Note the size of the "@Message" parameter. log4net is taking a guess at how to convert the type and (I think) converting it to nvarchar even though the column is a varchar. This is a big deal because nvarchar has a max size of 4000 while varchar has a max size of 8000.
The DBA saw errors as described in this KB article: http://support.microsoft.com/kb/827366
I changed the size to 4000 and everything works swimingly.
Hopefully this will help somebody else avoid the same problem.
Cheers!