问题
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