logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Can't log nulls with AdoNetAppender?
Date Fri, 18 Nov 2005 11:01:09 GMT
The AdoNetAppender has been updated to support logging of null values
(mapping null to DBNull), this update has not yet made it into a release
and is only available in the source code repository. You can checkout
the latest source from the SVN repository and build your own custom
build of log4net that has the fix in, or you could just get the latest
source for the AdoNetAppender and build that into a separate assembly
and use that with your current version of log4net.

Nicko

> -----Original Message-----
> From: Billy Barnum [mailto:b.barnum@comcast.net] 
> Sent: 14 November 2005 23:07
> To: 'Log4NET User'
> Subject: Can't log nulls with AdoNetAppender?
> 
> My client is having me log to a SQL Server database using 
> AdoNetAppender.
> All is going smoothly except for one thing: I can't seem get 
> NULL values into database columns. Certain of the database 
> columns are of SQL Server type Int (.NET type Int32) because 
> they are primary key values in other tables and need to 
> participate in joins - but the columns allow nulls; 
> occasionally they aren't present. Whenever I pass 
> System.DBNull.Value, the logevent never makes it to the database. 
> 
> My code does this:
> 
> loggingEvent.Properties["BusinessId"] = prmBusinessId; <--- 
> 1234 works here; System.DBNull.Value does not.
> 
> and the corresponding parameter in my config file is this:
> 
> <parameter>
> 	<parameterName value="@prmBusinessId" />
> 	<dbType value="Int32" />
> 	<size value="4" />
> 	<layout type="log4net.Layout.PatternLayout">
> 		<conversionPattern value="%X{BusinessId}" />
> 	</layout>
> </parameter>
> 
> I've included internal debug output below, but I get the 
> *exact same format exception error* for successful writes to 
> the database and unsuccessful ones. SQL Server Profiler does 
> not show the statement at all when I pass in DBNulls, from 
> which I infer that log4net is choking on the null and not 
> even making the attempt.
> 
> Is there no way to get nulls into these columns, or am I 
> doing something wrong?
> 
> -BillyB
> 
> WILLIAM BARNUM
> b.barnum@comcast.net
> 
> log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
> log4net: XmlHierarchyConfigurator: Logger [root] Level string 
> is [DEBUG].
> log4net: XmlHierarchyConfigurator: Logger [root] level set to 
> [name="DEBUG",value=30000].
> log4net: XmlHierarchyConfigurator: Loading Appender 
> [SqlServerAppender]
> type: [log4net.Appender.AdoNetAppender]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [LevelMin] to Level value [DEBUG]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [LevelMax] to Level value [FATAL]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddFilter] to object [log4net.Filter.LevelRangeFilter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [BufferSize] to Int32 value [1]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConnectionType] to String value 
> [System.Data.SqlClient.SqlConnection, System.Data, 
> Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConnectionString] to String value [Data 
> Source=BMT00002;Database=WIAN;User
> Id=wianuser;Password=wianuser;]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [Credentials] to ImpersonationMode value [Process]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [SecurityContext] to object [log4net.Util.WindowsSecurityContext]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [CommandType] to CommandType value [StoredProcedure]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [CommandText] to String value [dbo.EventLogInsStd]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmEventSource]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [32]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{EventSource}]
> log4net: PatternParser: Converter [property] Option 
> [EventSource] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmEventType]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [32]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{EventType}]
> log4net: PatternParser: Converter [property] Option 
> [EventType] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmBusinessId]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [Int32]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [4]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%X{BusinessId}]
> log4net: PatternParser: Converter [X] Option [BusinessId] 
> Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmWIANOrderId]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [Int32]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [4]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{WIANOrderId}]
> log4net: PatternParser: Converter [property] Option 
> [WIANOrderId] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmCustomerId]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [Int32]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [4]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{CustomerId}]
> log4net: PatternParser: Converter [property] Option 
> [CustomerId] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmCodePoint]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [32]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{CodePoint}]
> log4net: PatternParser: Converter [property] Option 
> [CodePoint] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmComputerUserId]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [16]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{ComputerUserId}]
> log4net: PatternParser: Converter [property] Option 
> [ComputerUserId] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmEmployeeId]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [Int32]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [4]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{EmployeeId}]
> log4net: PatternParser: Converter [property] Option 
> [EmployeeId] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmEmployeeFirstName]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [32]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{EmployeeFirstName}]
> log4net: PatternParser: Converter [property] Option 
> [EmployeeFirstName] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmEmployeeLastName]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [32]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%property{EmployeeLastName}]
> log4net: PatternParser: Converter [property] Option 
> [EmployeeLastName] Format [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ParameterName] to String value [@prmEventText]
> log4net: XmlHierarchyConfigurator: Setting Property [DbType] 
> to DbType value [String]
> log4net: XmlHierarchyConfigurator: Setting Property [Size] to 
> Int32 value [2048]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: PatternParser: Converter [newline] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property 
> [ConversionPattern] to String value [%message]
> log4net: PatternParser: Converter [message] Option [] Format 
> [min=-1,max=2147483647,leftAlign=False]
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] 
> to object [log4net.Layout.Layout2RawLayoutAdapter]
> log4net: XmlHierarchyConfigurator: Setting Collection 
> Property [AddParameter] to object 
> [log4net.Appender.AdoNetAppenderParameter]
> log4net: XmlHierarchyConfigurator: Created Appender 
> [SqlServerAppender]
> log4net: XmlHierarchyConfigurator: Adding appender named 
> [SqlServerAppender] to logger [root].
> log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
> '/LM/w3svc/1/root/log4netTest-5-127765108162748686': Loaded 
> 'c:\windows\microsoft.net\framework\v1.1.4322\temporary 
> asp.net files\log4nettest\3367badd\2fed7587\l6xcisvj.dll', 
> Symbols loaded.
> log4net:ERROR [AdoNetAppender] Exception while writing to database
> System.FormatException: Input string was not in a correct format.
>    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
>    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
>    at 
> log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction 
> dbTran, LoggingEvent[] events)
>    at 
> log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] 
> events) log4net:ERROR [AdoNetAppender] Exception while 
> writing to database
> System.FormatException: Input string was not in a correct format.
>    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
>    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
>    at 
> log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction 
> dbTran, LoggingEvent[] events)
>    at 
> log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
>  
> 
> 

Mime
View raw message