It is quite simple actually:
1. Make sure to add the Exception column to your table.
CREATE TABLE [dbo].[Log]( [ID] [int] IDENTITY(1,1) NOT NULL, [Date] [datetime] NOT NULL, [Thread] [varchar](255) NOT NULL, [Level] [varchar](20) NOT NULL, [Logger] [varchar](255) NOT NULL, [Message] [varchar](4000) NOT NULL, [Exception] [varchar](2000) NULL ) ON [PRIMARY]
2. Extend the CommandText value to include the Exception parameter:
<param name="CommandText" value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />3. Finally, add the following parameter to the log4net configuration. Note that special “Exception” layout is used.
The value of the sizeparameter should match the size of the SQL column on #1.
<param name="Parameter"> <param name="ParameterName" value="@exception" /> <dbType value="String" /> <size value="2000" /> <layout type="log4net.Layout.ExceptionLayout" /> </param>Now you are all set, and should be able to see exceptions in the database:
Cheers!
1 comments:
Great stuff,
One question: currently the exception-field is containing a text that contains 3 parts: "exception", "message" and "source"
Is it possible to change this to be logged in seperate database columns?
Regards, Nico Lubbers
Post a Comment