开发者

log4net: dismember exception

开发者 https://www.devze.com 2023-03-26 03:57 出处:网络
I want to separate exception\'s stack trace from their message. for instance in this example: System.NullReferenceException: Object reference not set to an instance

I want to separate exception's stack trace from their message. for instance in this example:

System.NullReferenceException: Object reference not set to an instance of an object.

at BettweenSvc.Bettweensvc.processRequest(RequestManagerRepository rmr, RequestConversation rc) in C:\Repository\bettween\trunk\Solution\BettweenSvc\Bettweensvc.cs:line 277

at BettweenSvc.Bettweensvc.bettweenTimer_Elapsed(Object sender, ElapsedEventArgs e) in C:\Repository\bettween\trunk\Solution\BettweenSvc\Bettweensvc.cs:line 111

I want to log

开发者_如何转开发

System.NullReferenceException: Object reference not set to an instance of an object.

in one field and the rest in another

Currently I have

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

in my AdoNetAppender, how would I do this?


This should work:

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

If you want the stacktrace you use %exception{stacktrace}.

EDIT:
If you are using log4net 1.2.10 then you need to implement your own pattern layout that does what you want. I recommend to check the current log4net source code (trunk) to see how they do it (it is quite simple really). Here is an example of such a layout converter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号