views:

493

answers:

1

Hi, my config file below: very strange, i have spent a day to find out where i am wrong, but still not working, it still not log anything in the database,but i can output them using RollingFileAppender. Also, the store procedure WriteLog is working well.(I have tested it using sql server studio). I have tried to change the connectionType but not working. Unfortunately I dont have sql server 2000/2005 to test, my log4net version should be the latest one: log4net 1.2.10. Any help is appreciated.

<?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>
A: 

Best way to determine what is going wrong is to use dbgview from Sysinternals. If the logging fails you will probably see error messages appearing there.

sgmoore
Thanks for your response. I have found the problem, it is because "<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />" i have double output "System.Data, System.Data", the log4net does work for sql server 2008, thank you again!
schrodinger's code

related questions