我在配置a StringMatchFilter以匹配消息中的字符串与换行符时遇到问题.我想跳过一些消息,我添加了一个这样的过滤器,它可以工作.
<filter type="log4net.Filter.StringMatchFilter">
<param name="AcceptOnMatch" value="false" />
<stringToMatch value="Unexpected exception in SocketThreadWorker" />
</filter>
Run Code Online (Sandbox Code Playgroud)
但是,如果我stringToMatch将消息的第二行更改为"远程主机强制关闭的现有连接",则过滤器不起作用.是因为消息中的换行符还是我在这里做错了什么?
典型的消息可能如下所示:
------示例消息----------------------------
2011-05-04 16:22:24,078 [Client (connected from "127.0.0.1:4076" at 16:22)] ERROR - Unexpected exception in SocketThreadWorker System.Net.Sockets.SocketException:
An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
Run Code Online (Sandbox Code Playgroud)
------结束示例消息---------------------------
"SocketThreadWorker中出现意外异常"位于消息的第一行,"强制关闭现有连接"位于第二行.
编辑
appender看起来像这样:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<filter type="log4net.Filter.StringMatchFilter">
<param name="AcceptOnMatch" value="false" />
<stringToMatch value="An existing connection was forcibly closed by the remote host" />
</filter>
<to value="..." />
<from value="..." …Run Code Online (Sandbox Code Playgroud)