是否有可能从特定线程中过滤掉日志条目?
我使用 nunit 运行测试(c#):
using System;
using NUnit.Core;
using log4net;
namespace Main
{
public class Program
{
public static readonly ILogger log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
log.Info("start");
TestPackage package = new TestPackage(@"C:\Test\Main.Tests.dll");
RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
remoteTestRunner.Load(package);
TestResult result = remoteTestRunner.Run(new NullListener(), TestFilter.Empty, true, LoggingThreshold.All);
log.Info("end");
}
}
}
这是我得到的日志:
INFO 17:57:24 [1] Main.Program - start
ERROR 17:57:25 [TestRunnerThread] Main.TestedClass - Exception! Relevant for production / okay in test
INFO 17:57:26 [1] Main.Program - end
每次记录错误时,log4net 都会向我发送一封邮件。如果我运行测试,我不想收到这些邮件。nunit 将线程名称设置为:“TestRunnerThread”。我怎么能忽略这个线程?
我读过这篇文章:如何使用 Log4Net 登录到每个线程的单独文件?并尝试了这个过滤器(根本没有日志):
<filter type="log4net.Filter.PropertyFilter">
<key value="threadId" />
<stringToMatch value="TestRunnerThread" />
<acceptOnMatch value="false" />
</filter>