我有一个带有多个appender的控制台程序(.Net 4.5)。文件appender工作正常,一些smtp appender工作,一个没有。
除非 SmtpAppenderError 没有发送任何内容,否 我试着:
在大多数情况下,使用文件,Ok和Error appender,无论如何DELETE工作正常,即使其他appender队列中有消息。 你有什么想法吗?
这是我的配置:
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\\Log\\myprogram\\log-" />
<datePattern value="yyyy-MM.dd'.log'" />
<param name="AppendToFile" value="true" />
<param name="Encoding" value="utf-8" />
<param name="RollingStyle" value="Date" />
<param name="StaticLogFileName" value="false" />
<param name="maxSizeRollBackups" value="90" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%5p [%d] - %m%n" />
</layout>
</appender>
<appender name="SmtpAppenderError" type="log4net.Appender.SmtpAppender">
<to value="a.b@c.com" />
<from value="sender@somewhere.com" />
<subject value="Error in program" />
<smtpHost value="mail.somewhere.com" />
<port value="25" />
<authentication value="Basic" />
<username value="user@somewhere.com" />
<password value="secret!" />
<bufferSize value="9999" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date - %message%newline" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="ERROR:" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<appender name="SmtpAppenderOK" type="log4net.Appender.SmtpAppender">
<to value="a.b@c.com" />
<from value="sender@somewhere.com" />
<subject value="All right!" />
<smtpHost value="mail.somewhere.com" />
<port value="25" />
<authentication value="Basic" />
<username value="mail@somewhere.com" />
<password value="secret!" />
<bufferSize value="9999" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date - %message%newline" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="FP:" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<appender name="SmtpAppenderDELETE" type="log4net.Appender.SmtpAppender">
<to value="a.b@c.com" />
<from value="sender@somewhere.com" />
<subject value="deleting..." />
<smtpHost value="mail.somewhere.com" />
<port value="25" />
<authentication value="Basic" />
<username value="mail@somewhere.com" />
<password value="secret!" />
<bufferSize value="999" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date - %message%newline" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="FP:delete" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="SmtpAppenderError" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="SmtpAppenderOK" />
<appender-ref ref="SmtpAppenderDELETE" />
</root>
答案 0 :(得分:1)
我通过更改appender的顺序解决了这个问题,首先是所有SMTP,然后是文件appender。