nlog 什么时候过滤器不生效?
nlog when filter not taking effect?
我的 nlog.config 中有这个 rule
。 (还有其他规则,但这是唯一一个最终发送电子邮件的规则,因此也是唯一要调试的规则):
<rules>
<logger name="*cxml*" minlevel="Info" writeto="customer">
<filters>
<when condition="not equals('${aspnet-request:serverVariable=HTTP_HOST},'interestinghost.com')" action="ignore" />
</filters>
</logger>
</rules>
这应确保 Info 级别的消息,来自记录器名称中带有 cxml 的记录器,应写入 客户目标;但是当 HTTP_HOST
服务器变量不等于 interestinghost.com 时,应该忽略信息消息。因此,只有关于 interestinghost.com 的消息才应该通过电子邮件发送。
客户 目标发送电子邮件,并具有此定义。请注意,布局包括 HTTP_HOST
变量:
<target name="customer" xsi:type="Mail"
smtpServer="..." smtpPort="587" smtpAuthentication="Basic"
smtpUserName="..." smtpPassword="..." enableSsl="true"
from="..." to="..." cc="..."
subject="log from ${logger} ${longdate}"
layout="===================${aspnet-request:serverVariable=REQUEST_METHOD} ${aspnet-request:serverVariable=SERVER_PORT} ${aspnet-request:serverVariable=HTTP_HOST}${aspnet-request:serverVariable=URL} ${aspnet-request:serverVariable=QUERY_STRING} ${newline}${level} | ${longdate} | ${logger} ${stacktrace:topframes=5}| ${message} | ${exception:format=Message,ShortType,StackTrace}"
encoding="iso-8859-2" />
尽管如此,我的实际客户报告说他收到了他不应该收到的消息 -- 特别是指向另一个人的消息 HTTP_HOST
:
===================POST 80 boring.noninteresting.host/cxml/setup
Warn | 2016-06-15 13:33:38.4817 | application.page.logger => Page.ProcessRequest => Page.ProcessRequestMain => Control.LoadRecursive => cxmlSetup.Page_Load => LoggerImpl.Write| Sending cXML PunchOutSetupResponse message:
<?xml version="1.0" encoding="utf-16"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML xml:lang="en-US" payloadID....
这怎么可能发生?
您的函数在右大括号和逗号之间缺少单引号。
↓↓
not equals('${aspnet-request:serverVariable=HTTP_HOST},'interestinghost.com')
我的 nlog.config 中有这个 rule
。 (还有其他规则,但这是唯一一个最终发送电子邮件的规则,因此也是唯一要调试的规则):
<rules>
<logger name="*cxml*" minlevel="Info" writeto="customer">
<filters>
<when condition="not equals('${aspnet-request:serverVariable=HTTP_HOST},'interestinghost.com')" action="ignore" />
</filters>
</logger>
</rules>
这应确保 Info 级别的消息,来自记录器名称中带有 cxml 的记录器,应写入 客户目标;但是当 HTTP_HOST
服务器变量不等于 interestinghost.com 时,应该忽略信息消息。因此,只有关于 interestinghost.com 的消息才应该通过电子邮件发送。
客户 目标发送电子邮件,并具有此定义。请注意,布局包括 HTTP_HOST
变量:
<target name="customer" xsi:type="Mail"
smtpServer="..." smtpPort="587" smtpAuthentication="Basic"
smtpUserName="..." smtpPassword="..." enableSsl="true"
from="..." to="..." cc="..."
subject="log from ${logger} ${longdate}"
layout="===================${aspnet-request:serverVariable=REQUEST_METHOD} ${aspnet-request:serverVariable=SERVER_PORT} ${aspnet-request:serverVariable=HTTP_HOST}${aspnet-request:serverVariable=URL} ${aspnet-request:serverVariable=QUERY_STRING} ${newline}${level} | ${longdate} | ${logger} ${stacktrace:topframes=5}| ${message} | ${exception:format=Message,ShortType,StackTrace}"
encoding="iso-8859-2" />
尽管如此,我的实际客户报告说他收到了他不应该收到的消息 -- 特别是指向另一个人的消息 HTTP_HOST
:
===================POST 80 boring.noninteresting.host/cxml/setup
Warn | 2016-06-15 13:33:38.4817 | application.page.logger => Page.ProcessRequest => Page.ProcessRequestMain => Control.LoadRecursive => cxmlSetup.Page_Load => LoggerImpl.Write| Sending cXML PunchOutSetupResponse message:
<?xml version="1.0" encoding="utf-16"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML xml:lang="en-US" payloadID....
这怎么可能发生?
您的函数在右大括号和逗号之间缺少单引号。
↓↓
not equals('${aspnet-request:serverVariable=HTTP_HOST},'interestinghost.com')