如何在 log4net ADONetAppender 中使用存储过程?

发布于 2024-07-06 06:07:21 字数 2037 浏览 13 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌能量女王 2024-07-13 06:07:21

使用“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

(り薆情海 2024-07-13 06:07:21

感谢一位警惕的 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!

想念有你 2024-07-13 06:07:21
</configSections>
<log4net>

    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">

        <bufferSize value="1"/>

        <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

        <connectionString value="Data Source=yourservername;initial Catalog=Databasename;User ID=sa;Password=xyz;"/>



        <commandText value="INSERT INTO Log4Net ([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 ip=%property{ip}"/>

            </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>
</configSections>
<log4net>

    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">

        <bufferSize value="1"/>

        <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

        <connectionString value="Data Source=yourservername;initial Catalog=Databasename;User ID=sa;Password=xyz;"/>



        <commandText value="INSERT INTO Log4Net ([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 ip=%property{ip}"/>

            </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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文