As as follow up to the about SQL based logging in , here is another quick tip about how to include exception stack trace into your log database.

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**
  1. 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**)" />
  1. 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**" />

Now you are all set, and should be able to see exceptions in the database: