Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net - Suppress "exception" from being appended to custom "PatternLayout"

When using a custom "PatternLayout", log4net is appending the "exception" information (when present) to every log entry. I am trying to control the output of the message and stack trace information and would like to "suppress" this information. I have searched around but cannot find a way to do it. Any ideas?

Sample web.config entry (for a RollingFileAppender):

<layout type="Example.Class.CustomLog4netLayouts,Example">    
    <conversionPattern value="%date [%thread] [RID:%property{CLIENT_REQUESTID}] 
     %-5level %logger [%property{NDC}] - %cleanmessage - %cleanstack%newline" />
</layout>

Thanks

like image 971
Frizzb Avatar asked Sep 12 '12 18:09

Frizzb


1 Answers

Configure the layout like this:

<layout type="Example.Class.CustomLog4netLayouts,Example">
    <IgnoresException value="False" />
    ...

Setting IgnoresException to false tells the appender that the layout will take care of the exception. Thus you can choose not to print the stack trace.

like image 110
Stefan Egli Avatar answered Nov 04 '22 09:11

Stefan Egli