Log4net - Suppress “exception” from being appended to custom “PatternLayout”

只谈情不闲聊 提交于 2020-03-15 19:28:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/12394165/log4net-suppress-exception-from-being-appended-to-custom-patternlayout

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