Log4Net - Logging out the Exception stacktrace only for certain files

半腔热情 提交于 2019-11-27 18:48:59

Configure the layout like this (GeneralTextLog Appender):

<layout type="log4net.Layout.PatternLayout">
    <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.

From your configuration, it looks like your stack trace was included as part of your message parameter.

EDIT -- I should have been clearer. My guess is that when you called log4net's logging methods, your first parameter (which is message) contained the stack trace, but that's just a guess. It's also the only parameter in both of your appenders. If you don't have a parameter in your appender format, it shouldn't appear in both logs... unless of course your appender with the exception is the primary appender.

Try this instead and see what happens:

<!-- Loggers -->
<root>
  <appender-ref ref="GeneralTextLog"/>
  <level value="ALL"/>
</root>

<logger name="ErrorLogger">
  <appender-ref ref="ErrorTextLog"/>
  <levelMin value="WARN"/>
  <levelMax value="FATAL"/>
</logger>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!