是否可以将 log4net 配置为具有两个 smtp 附加程序 - 一个仅在日志级别 >= WARN 时发送电子邮件,第二个发送所有内容,但不能同时发送两个。
<appender name="SmtpAppenderWarn" type="log4net.Appender.SmtpAppender">
<to value="to@domain.com" />
<from value="from@domain.com" />
<subject value="Import completed with warnings / errors" />
<smtpHost value="localhost" />
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
</layout>
</appender>
<appender name="SmtpAppenderSuccess" type="log4net.Appender.SmtpAppender">
<to value="to@domain.com" />
<from value="from@domain.com" />
<subject value="Import completed successfully" />
<smtpHost value="localhost" />
<bufferSize value="512" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger: %message%newline" />
</layout>
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
</appender>
我的应用程序有:
Log.Info("Importer is starting...");
//my logic
//if warn Log.Warn("Warning...");
Log.Info("Import finished");
所以我一直在使用 INFO。现在,当我遇到 WARN 时,两条消息都在发送。我当然希望没有发送带有成功信息的那个。