Log4Net - Logging out the Exception stacktrace only for certain files

后端 未结 2 1818
[愿得一人]
[愿得一人] 2020-12-05 00:36

I currently have multiple log files in my application using log4net.

I have a top level log file which contains every type of message. I also have an error log file

相关标签:
2条回答
  • 2020-12-05 01:17

    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>
    
    0 讨论(0)
  • 2020-12-05 01:36

    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.

    0 讨论(0)
提交回复
热议问题