2

Is there any known approach for logging different information depending on the exception type?

The idea would be only log relevant information per exception type. eg: known exceptions/business logic exceptions don't need a stack trace logged, since they are "expected"

Basically what I'm asking is if there are any known practices while logging exceptions to make the log as helpful as possible w/o any trash.

Hélder Gonçalves
  • 3,822
  • 13
  • 38
  • 63

1 Answers1

3

You can filter in the <rules>, e.g.

<rules>
    <logger name="*" writeTo="file1">
        <filters>
            <when condition="'${exception:format=Type}' == 'ExpectedException' " action="LogFinal" />
            <when condition="true" action="Ignore" />

        </filters>
    </logger>
    <logger name="*" writeTo="file2">
        <filters>
            <when condition="'${exception:format=Type}' == 'OtherException' " action="LogFinal" />
            <when condition="true" action="Ignore" />

        </filters>
    </logger>    
</rules>

See when filter and conditions docs.

Julian
  • 33,915
  • 22
  • 119
  • 174