tags:

views:

22

answers:

2

I am using the AdoNetAppender and here is a portion of my config file

 <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
  <bufferSize value="1" /> 
  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <connectionString value="[we will set this automatically at runtime]" />
  <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>

and this is my code to log messages

 private static readonly ILog fifthlog = LogManager.GetLogger("ADONetAppender"); fifthlog.Info("this is db log");

i'm also using other appenders like rollingfileappender, and they are working perfectly but this one doesnt, because when i do this query "select * from Log" in my sql server the table is empty. and my db connection is succesful coz i tested the connection. Whats Wrong?

A: 

Does the account have insert permissions on the Log table?

And what is the configured output level for this appender?

devstuff
A: 

In order to really find out what is happening you should enable internal debugging:

http://log4net.sourceforge.net/release/1.2.0.30316/doc/manual/faq.html#internalDebug

A few things that come to my mind:

  • Permission issue on the database (as pointed out by devstuff already)
  • If you use integrated security: It could be that you connect with the caller instead of the host process (this happens for instance if you have a sharepoint environment).
  • Conversion problem with one of your parameters (though this seems unlikely)
Stefan Egli
thnx i got it fixed it was the connection and permissions
Precious