log4net adding full stack trace to database table via exception parameter

丶灬走出姿态 提交于 2020-01-04 03:28:07

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10219407/log4net-adding-full-stack-trace-to-database-table-via-exception-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!