我正在使用 log4net。
当应用程序给出错误时,我想发送电子邮件只是为了错误。我该怎么做?
我的配置文件:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net>
<appender name="SMTPAppender" type="log4net.Appender.SMTPAppender">
<authentication value="Basic" />
<to value="xxx@xxx" />
<from value="yyy@yyy" />
<username value="user" />
<password value="pass" />
<subject value="ERROR" />
<smtpHost value="host" />
<port value="25" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN" />
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger %newline %message%newline%newline%newline" />
</layout>
</appender>
<root>
<level value="INFO"></level>
</root>
<logger name="SMTPAppender">
<level value="INFO"></level>
<appender-ref ref="SMTPAppender"></appender-ref>
</logger>
</log4net>
</configuration>
我正在尝试在 NUnit 中进行测试:
[TestFixture]
public class TestClass
{
[Test]
public void Test()
{
ILog logger = LogManager.GetLogger(typeof(TestClass));
logger.Error("test mail");
}
}
我可能做错了什么。
编辑:
<logger name="Yuartz.Tests.TestClass">
<level value="INFO"></level>
<appender-ref ref="SMTPAppender"></appender-ref>
</logger>
namespace Yuartz.Tests
{
using log4net;
using log4net.Config;
[TestFixture]
public class TestClass
{
[Test]
public void Test()
{
XmlConfigurator.Configure();
var logger = LogManager.GetLogger("SMTPAppender");
logger.Error("test mail");
logger.Info("test mail");
}
}
}