gpt4 book ai didi

asp.net - 如何在 SQL Server 的 log4net 配置中使用存储过程进行日志记录

转载 作者:行者123 更新时间:2023-12-02 21:08:47 26 4
gpt4 key购买 nike

如何更新存储过程的 commandText 和参数部分,以便可以通过 log4net 将错误记录到 SQL Server 中?

我使用的是 SQL Server 2008,我的附加程序配置如下所示:

<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
<bufferSize value="100"/>
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<connectionString value="server=MYSERVER; uid=MYUSER; pwd=MYPASS; database=MYDB"/>
<commandText
value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)"

/>
<parameter>
<parameterName value="@log_date"/>
<dbType value="DateTime"/>
<layout type="log4net.Layout.RawTimeStampLayout"/>
</parameter>
<parameter>
<parameterName value="@thread"/>
<dbType value="String"/> <size value="255"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread"/>
</layout>
</parameter>
<parameter>
<parameterName value="@log_level"/>
<dbType value="String"/>
<size value="50"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level"/>
</layout>
</parameter>
<parameter>
<parameterName value="@logger"/>
<dbType value="String"/>
<size value="255"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger"/>
</layout>
</parameter>
<parameter>
<parameterName value="@message"/>
<dbType value="String"/>
<size value="4000"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message"/>
</layout>
</parameter>
<parameter>
<parameterName value="@exception"/>
<dbType value="String"/>
<size value="2000"/>
<layout type="log4net.Layout.ExceptionLayout"/>
</parameter>
</appender>

最佳答案

尝试一下:

 <commandText value="StorProcName" />
<commandType value="StoredProcedure" />

<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
... all parameters ...

log4net online config examples page :

The CommandText is either a prepared statement or a stored procedure. Each parameter to the prepared statement or stored procedure is specified with its name, database type and a layout that renders the value for the parameter.

关于asp.net - 如何在 SQL Server 的 log4net 配置中使用存储过程进行日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10034055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com