Ayende @ Rahien

Unnatural acts on source code

Fixing log4net 1.2.9 AdoNetAppender NULL bug

In log4net 1.2.9 there is a bug in the AdoNetAppender. It will not log null values appropriately. This bug is fixed in log4net 1.2.10, but it is not always possible to move to the next version. (In my case, both NHibernate and Castle uses log4net 1.2.9)

I tried recompiling everything to use 1.2.10, but it took too long, and eventually I simply wrote this little trigger:

CREATE TRIGGER [ReplaceNullLookAlikeWithNulls]

   ON  [dbo].[Logs]

   INSTEAD OF INSERT

AS

BEGIN

      -- SET NOCOUNT ON added to prevent extra result sets from

      -- interfering with SELECT statements.

      SET NOCOUNT ON;

 

   INSERT INTO .[dbo].[Logs]

           ([Date]

           ,[Thread]

           ,[Level]

           ,[Logger]

           ,[Message]

           ,[Exception]

           ,[Filename]

      SELECT

              [Date]

              ,[Thread]

              ,[Level]

              ,[Logger]

              ,[Message]

              ,[Exception]

              ,case [Filename] when '(null)' then NULL else [Filename] end

       FROM Inserted

END

Not the best solution, but it will hold water.

Comments

No comments posted yet.

Comments have been closed on this topic.