Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have read the docs on this, but I can't get an NLog logger to contain only lines that contain a fixed substring. I am using the code below. The file is written but contains all logging output, just the same as another log I have that has no filter.

Can anyone please tell me what I am doing wrong?

<rules>
<logger name="*" minlevel="Trace" writeTo="DataStore">
<filters>
<when condition="contains('${message}','XXXX')" action="LogFinal"/>
</filters>
</logger>
</rules>

What I have tried:

I honestly can't think of what else to try right now. The above code looks dead simple and I don't see why it shouldn't work.
Posted
Updated 12-Sep-17 7:17am

1 solution

The answer to this is (as I suspected) annoyingly obvious. The clue is in the name. These things are called 'filters', so they don't say what should be written to the log; they say what should not be written to the log.

So, it works if I change the filter to:

<when condition="not contains('${message}','XXXX')" action="Ignore"/>
 
Share this answer
 
Comments
Richard Deeming 12-Sep-17 15:58pm    
The term "filter" seems to be used interchangeably to mean both "only include items that match this" and "don't include items that match this", so it's not as obvious as you might think! :)
Patrick Skelton 13-Sep-17 3:30am    
Very good point. I have to say that I found the whole thing - including the documentation - to be less than intuitive.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900