Nicko, I tried this change but got a new exception:
[2176] log4net:ERROR [AdoNetAppender] Exception while writing to database [2176] System.Data.SqlClient.SqlException: Prepared statement '(@date datetime,@level nvarchar(50),@appdomain nvarchar(255),@lo' expects parameter @spid, which was not supplied. [2176] at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) [2176] at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() [2176] at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) in c:\Work\cvs_root\apache\r1.2.9\logging-log4net\build\package\log4net-1.2 .9-beta\src\Appender\AdoNetAppender.cs:line 550 [2176] at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events) in c:\Work\cvs_root\apache\r1.2.9\logging-log4net\build\package\log4net-1.2 .9-beta\src\Appender\AdoNetAppender.cs:line 460 -----Original Message----- From: Nicko Cadell [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 26, 2005 12:35 AM To: Log4NET User Subject: RE: Null values for int (revised) Howard, Try specifying the int param using the RawPropertyLayout. This layout does no conversion on the value found (or null if not found) in the properties dictionary. <parameter> <parameterName value="@spid" /> <dbType value="Int32" /> <layout type="log4net.Layout.RawPropertyLayout"> <key value="spid" /> </layout> </parameter> Nicko > -----Original Message----- > From: Howard Weisberg [mailto:[EMAIL PROTECTED] > Sent: 26 April 2005 01:26 > To: Log4NET User > Subject: RE: Null values for int (revised) > > 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.
