log4net adding full stack trace to database table via exception parameter
Asked Answered
M

1

3

For log4net configuration.. here is my parameter setting

    <parameter>
      <parameterName value="@exception"/>
      <dbType value="String"/>
      <size value="8000"/>
      <layout type="log4net.Layout.ExceptionLayout"/>
    </parameter>
  </appender>

My stored proc in ADONetAppender is set as follows:

<commandText value="dbo.MyInsertProcName"/>
<commandType value="StoredProcedure"/>

Inside the proc, the input parameter for @exception is as follows:

ALTER PROCEDURE [dbo].[MyInsertProcName]        
(    
    @log_date               DATETIME        
    , @log_level            VARCHAR(50)        
    , @logger               VARCHAR(255)        
    , @message              VARCHAR(4000)        
    , @exception            VARCHAR(MAX) 
....

The stored proc writes to the table "MYTable" which has "Exception" column length as VARCHAR 8000.

I am able to create entry into the "MYTable" but this entry does not contain the whole exception stack trace after entry is created. It looks like the stack trace is truncated and only contains upto to 1700 characters.

what is the best way of logging full stack trace to the database in log4net?

What am I missing?

Please help.

Thanks

Mince answered 18/4, 2012 at 23:8 Comment(0)
G
7

I usually use this (I have a nvarchar(max) field):

<parameter>
  <parameterName value="@exception"/>
  <dbType value="String"/>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%exception" />
  </layout>
</parameter>

I assume however that it should also work with your configuration if you remove the size parameter or set it to -1.

Greasepaint answered 19/4, 2012 at 7:41 Comment(2)
Just as a note: omitting the size element didn't work for me, but, setting it to -1 did work. Go figure.Helgoland
neither option works for me. My message column is being truncated. Any ideas?Foundling

© 2022 - 2024 — McMap. All rights reserved.