通过log4net的异常参数添加完整的堆栈跟踪到数据库表 [英] log4net adding full stack trace to database table via exception parameter

查看:436
本文介绍了通过log4net的异常参数添加完整的堆栈跟踪到数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关log4net的配置。这里是我的参数设置。

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>

在ADONetAppender我的存储过程的设置如下:

My stored proc in ADONetAppender is set as follows:

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

在proc内部,用于抛出输入参数为如下所示:

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) 
....

该存储过程写入表MYTABLE里面有异常列的长度为VARCHAR 8000。

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

我能够创造进入MYTABLE,但是这条目不包含全异常堆栈跟踪中创建条目之后。它看起来像堆栈跟踪被截断,只包含高达1700个字符。

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.

什么记录完整的堆栈跟踪到数据库中log4net的?

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

我在想什么?

请帮忙。

感谢

推荐答案

我通常使用这个(我有一个为nvarchar(最大)字段):

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>

然而

我认为它也应该与你的配置工作,如果你删除的大小参数或将其设置为-1。

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

这篇关于通过log4net的异常参数添加完整的堆栈跟踪到数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆