2

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?

bevacqua
  • 47,502
  • 56
  • 171
  • 285

1 Answers1

2

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.

Community
  • 1
  • 1
Stefan Egli
  • 17,398
  • 3
  • 54
  • 75