log4net AdoNetAppender是否支持sql server 2008?

时间:2009-07-31 06:13:03

标签: sql-server-2008 log4net

我的配置文件如下:非常奇怪,我花了一天时间找出我错在哪里,但仍然无法正常工作,它仍然没有在数据库中记录任何内容,但我可以使用RollingFileAppender输出它们。此外,存储过程WriteLog运行良好。(我已经使用sql server studio测试了它)。我试图更改connectionType但不工作。 不幸的是我没有sql server 2000/2005来测试,我的log4net版本应该是最新版本:log4net 1.2.10。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
      <appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
        <!--<threshold value="OFF" />-->
        <bufferSize value="1" />
        <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <!--<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />-->
        <connectionString value="Data Source=.\MSSQLSERVER2008,2222;Initial Catalog=UnleashedSaaS;User ID=sa;Password=dogblack;" />
        <commandType value="StoredProcedure" />
        <commandText value="WriteLog" />
        <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
            </parameter>
      <parameter>
                <parameterName value="@thread" />
                <dbType value="String" />
                <size value="255" />
                <layout type="log4net.Layout.PatternLayout" value="%thread" />
            </parameter>
      <parameter>
                <parameterName value="@log_level" />
                <dbType value="String" />
                <size value="50" />
                <layout type="log4net.Layout.PatternLayout" value="%level" />
            </parameter>
      <parameter>
        <parameterName value="@logger" />
                  <dbType value="String" />
                  <size value="255" />
                  <layout type="log4net.Layout.PatternLayout" value="%logger" />
            </parameter>
      <parameter>
              <parameterName value="@message" />
              <dbType value="String" />
              <size value="4000" />
              <layout type="log4net.Layout.PatternLayout" value="%message" />
            </parameter>
         <parameter>
             <parameterName value="@exception" />
             <dbType value="String" />
             <size value="4000" />
             <layout type="log4net.Layout.ExceptionLayout" />
         </parameter>
      </appender>
      <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender" >
        <!--<threshold value="OFF" />-->
        <file value="LogData\\" />
        <appendToFile value="true" />
        <datePattern value="ul_yyyy-MM-dd.LOG" />
        <maxSizeRollBackups value="10" />
        <rollingStyle value="Date" />
        <maximumFileSize value="2MB" />
        <staticLogFileName value="false" />
        <layout type="log4net.Layout.PatternLayout">
          <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %u %c %l %m %n%n%n" />
        </layout>
      </appender>
      <root>
        <level value="ALL"/>
        <appender-ref ref="AdoNetAppender_SqlServer" />
        <appender-ref ref="RollingLogFileAppender" />
      </root>
    </log4net>
</configuration>

1 个答案:

答案 0 :(得分:0)

确定出错的最佳方法是使用Sysinternals中的dbgview。如果日志记录失败,您可能会看到出现错误消息。