过滤器没有生效时的nlog?

时间:2016-06-16 15:06:18

标签: nlog

我的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>

这应确保来自记录器名称中 cxml 的记录器的信息级别消息应写入客户目标;但是当HTTP_HOST服务器变量不等于 interestinghost.com 时,应忽略Info消息。因此,只有关于 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....

怎么可能发生这种情况?

1 个答案:

答案 0 :(得分:1)

你的功能上缺少单引号,右括号和逗号之间。

                                                     ↓↓
not equals('${aspnet-request:serverVariable=HTTP_HOST},'interestinghost.com')