I had a similar problem about a year back, ended up subclassing
AdoNetAppenderParameter and overriding the FormatValue method as below:

 public class MyAdoNetAppenderParameter : AdoNetAppenderParameter
 {
  /// <summary>
  /// Custom version of FormatValue method which also converts NullText
  value (null) to DBNull
  /// </summary>
  /// <param name="command"></param>
  /// <param name="loggingEvent"></param>
  public override void FormatValue(System.Data.IDbCommand command,
  log4net.Core.LoggingEvent loggingEvent)
  {
   // Lookup the parameter
   IDbDataParameter param =
   (IDbDataParameter)command.Parameters[ParameterName];

   // Format the value
   object formattedValue = Layout.Format(loggingEvent);

   // If the value is null then convert to a DBNull
   if ((formattedValue == null) || (formattedValue.ToString() ==
   SystemInfo.NullText))
   {
    formattedValue = DBNull.Value;
   }

   param.Value = formattedValue;
  }
 }

This can be intergrated with any other changes to your existing logging
code and only one minor change to the config file - set the type of the
parameter to that of your new class above.

Hope this helps.

Is there a better or recommended way of doing this?


-----bolikdimon <[EMAIL PROTECTED]> wrote: -----


To: log4net-user@logging.apache.org
From: bolikdimon <[EMAIL PROTECTED]>
Date: 01/08/2007 01:02PM
Subject: AdoNetAppender problem.


Hello. Help me please.
I'm using AdoNetAppender. How can I pass NULL value into stored procedure ?
Here is my code:
            ...
           ThreadContext.Properties["ProcessID"] = DbNull.Value;
           log.Debug(message);

Config-file:
     <parameter>
       <parameterName value="@ProcessID" />
       <dbType value="Int64" />
       <layout type="log4net.Layout.PatternLayout" value="%X{ProcessID}" />
     </parameter>

What's wrong ?

--
View this message in context:
http://www.nabble.com/AdoNetAppender-problem.-tf2939176.html#a8217407
Sent from the Log4net - Users mailing list archive at Nabble.com.



*********************************************************************************

Disclaimer: This electronic mail, together with any attachments, is for the 
exclusive and confidential use of the recipient addressee. Any other 
distribution, use or reproduction without our prior consent is unauthorised and 
strictly prohibited. If you have received this message in error, please delete 
it immediately and contact the sender directly or the Robert Wiseman & Sons Ltd 
IT Helpdesk on +44 (0)1355 270634. Any views or opinions expressed in this 
message are those of the author and do not necessarily represent those of 
Robert Wiseman & Sons Ltd or of any of its associated companies. No reliance 
may be placed on this message without written confirmation from an authorised 
representative of the company.

Robert Wiseman & Sons Limited reserves the right to monitor all e-mail 
communications through its network.

This message has been checked for viruses but the recipient is strongly advised 
to re-scan the message before opening any attachments or attached executable 
files.

********************************************************************************

Reply via email to