It seems to me that the handling of null values for properties of type
int is just broken. So my workaround is to deal with log4net as if the
only custom columns allowed are of type string.

If you have a custom property of type string, and your code has not
added a value for the property to Properties, the AdoNetAppender code
recognizes this and stores the following non-null string value in the
database: 

'(null)'

A corresponding hack does not seem to be included for ints -- if no
value for an int property has been added to Properties, and your
configuration follows one of the patterns in the documentation examples,
your event throws an exception and mysteriously fails to log. 

-----Original Message-----
From: Ron Grabowski [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 25, 2005 7:12 PM
To: Log4NET User
Subject: RE: Null values for int (revised)

The sproc would check for your magic number (values less than or equal
to zero) and insert a NULL value.

I don't know the exact sytnax for using a store procedure to log things
but I would imagine you need to do something like this:

 <commandText value="EventLogInsert @date, @spid" />  <commandType
value="System.Data.CommandType.StoredProcedure" />

--- Howard Weisberg <[EMAIL PROTECTED]> wrote:
> I think I can see from the documentation how to specify that I'm using

> an sproc. But I can't see what the sproc should do.
> 
> Is there an example in the documentation of how to use an sproc with 
> log4net?
> 
> -----Original Message-----
> From: Ron Grabowski [mailto:[EMAIL PROTECTED]
> Sent: Monday, April 25, 2005 5:32 PM
> To: Log4NET User
> Subject: RE: Null values for int (revised)
> 
> Perhaps you can use a stored procedure to write you logs to the 
> database instad of a simple INSERT statment.
> 
> --- Howard Weisberg <[EMAIL PROTECTED]> wrote:
> > I'm logging data using AdoNetAppender_SqlServer. Some of the info I
> 
> > want to log is best expressed in SQL columns of the int data type. 
> > Also some of the information is only defined during certain events.
> > 
> > Ideally, when I log other events, the undefined int information
> should
> 
> > be shown as SQL nulls. However so far I've only been able to figure
> 
> > out how to log int values using a "magic" numerical value (in my
> case
> > zero)
> > to flag undefined values. 
> > 
> > Null values do seem to be supported for string data.
> > 
> > The following doesn't work for me. It causes the SQL exception
> "data
> > is not in the correct format."
> > 
> > int spid = MyGetSPID (transaction);
> > log4net.GlobalContext.Properties["spid"] = spid;
> transaction.Commit();
> 
> > EventLog.Info ("Database Updated"); 
> > log4net.GlobalContext.Properties["spid"] = null;
> > //log4net.GlobalContext.Properties.Remove("spid") also doesn't
> work.
> > 
> > Instead I have to use the following:
> > 
> > const int UNDEFINED_VALUE = 0;
> > int spid = MyGetSPID (transaction);
> > log4net.GlobalContext.Properties["spid"] = spid;
> transaction.Commit();
> 
> > EventLog.Info ("Database Updated"); 
> > log4net.GlobalContext.Properties["spid"] = UNDEFINED_VALUE;
> > 
> > My config file includes the following:
> > 
> > <commandText value="INSERT INTO EventLog ([Date], ..., [SPID])
> VALUES
> > (@date, ..., @spid)" /> <parameter>
> >     <parameterName value="@date" />
> >     <dbType value="DateTime" />
> >     <layout type="log4net.Layout.PatternLayout"
> > value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" /> </parameter>
> > 
> > ...
> > 
> > <parameter>
> >     <parameterName value="@spid" />
> >     <dbType value="Int32" />
> >     <layout type="log4net.Layout.PatternLayout"
> > value="%property{spid}" /> </parameter>
> > 
> > My table includes the following:
> > 
> > CREATE TABLE EventLog
> > (
> >   [ID] [int] IDENTITY (1, 1) NOT NULL ,
> >   [Date] [datetime] NOT NULL ,
> > 
> > ...
> > 
> >   [SPID] [int]
> > )
> > 
> > How do I get log4net to handle null integer values? 
> > 
> > The information contained in this e-mail and any attached documents
> 
> > may be privileged, confidential and protected from disclosure.  If
> you
> 
> > are not the intended recipient you may not read, copy, distribute
> or
> > use this information.  If you have received this communication in 
> > error, please notify the sender immediately by replying to this 
> > message and then delete it from your system.
> > 
> 
> The information contained in this e-mail and any attached documents 
> may be privileged, confidential and protected from disclosure.  If you

> are not the intended recipient you may not read, copy, distribute or 
> use this information.  If you have received this communication in 
> error, please notify the sender immediately by replying to this 
> message and then delete it from your system.
> 

The information contained in this e-mail and any attached documents
may be privileged, confidential and protected from disclosure.  If you
are not the intended recipient you may not read, copy, distribute or
use this information.  If you have received this communication in
error, please notify the sender immediately by replying to this
message and then delete it from your system.

Reply via email to