如何过滤nlog记录器以仅包含包含子字符串的行? [英] How do I filter an nlog logger to contain only lines containing a substring?

查看:159
本文介绍了如何过滤nlog记录器以仅包含包含子字符串的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读过有关此文档的文档,但我无法获取NLog记录器以包含仅包含固定子字符串的 行。我正在使用下面的代码。该文件已写入但包含所有日志记录输出,就像我没有过滤器的另一个日志一样。



有谁能告诉我我做错了什么?



< rules>

< logger name =*minlevel =TracewriteTo =DataStore>

< filters>

< when condition =contains('$ {message}','XXXX')action =LogFinal/>

< / filters>

< / logger>

< / rules>



我尝试过的事情:



我真的想不出现在还能尝试什么。上面的代码看起来很简单,我不明白为什么它不应该工作。

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.

推荐答案

{message}','XXXX')action =LogFinal />

< / filters>

< / logger>

< / rules>



我尝试过的事情:



老实说,我想不出还有什么可以尝试的上面的代码看起来很简单,我不明白为什么它不起作用。
{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.


这个问题的答案(我怀疑)非常明显。这个线索就在名字中这些东西被称为过滤器,所以他们没有说应该写入日志;他们说什么不应该写入日志。



因此,如果我将过滤器更改为:



< when condition =not contained( '
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 =忽略/>
{message}','XXXX')" action="Ignore"/>


这篇关于如何过滤nlog记录器以仅包含包含子字符串的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆