1
votes

I'd like to setup a way to easily include/exclude certain log messages from an all encompassing log file. Throughout my code I've logged messages based on a "Context" property, which I was then going to use in when conditions to include/exclude the message.

Here is my setup:

<logger writeTo=""
        final="true">
  <filters>        
  <when condition="equals('${event-properties:item=Context}', 'Database')"
        action="Log"/>
  </filters>
</logger>

<logger name="*"
        minlevel="Trace"
        writeTo="default"/>

My hope was that I could include/exclude any messages with Context='Database' in the first logger and then change the writeTo attribute to either include the message (i.e. writeTo="default") or exclude (i.e. writeTo="").

The issue seems to be that the first logger is including ALL messages and since final is set to true, no messages are allowed to follow through to the catch all logger? Only logs matching the condition in the logger one are written as expected, however ALL logs are being "finalized" by it.

Any ideas a to what is wrong with my configuration?

1

1 Answers

2
votes

Maybe try this instead (Remove final="true" and instead use action="LogFinal")

<targets>
  <target xsi:type="Null" name="BlackHole" />
</targets>
<rules>
  <logger writeTo="BlackHole">
    <filters>        
       <when condition="equals('${event-properties:item=Context}', 'Database')"
         action="LogFinal"/>
    </filters>
  </logger>
</rules>

Looks like you have to specify an actual target to make the custom logger-filters work (Not dependent on LogLevel).