Esiste la possibilità di filtrare le voci di registro da una specifica discussione?log4net - confgure per ignorare i messaggi da una specifica discussione
posso utilizzare NUnit per l'esecuzione di test (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");
}
}
}
Questa è la registrazione ottengo:
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 mi manda una e-mail ogni volta che viene registrato un errore. Se eseguo il test, non voglio ricevere quelle mail. nunit imposta il nome del thread su: "TestRunnerThread". Come posso ignorare questo thread?
ho letto questo: How to log into separate files per thread with Log4Net? e ho cercato questo filtro (e non ho ricevuto i registri a tutti):
<filter type="log4net.Filter.PropertyFilter">
<key value="threadId" />
<stringToMatch value="TestRunnerThread" />
<acceptOnMatch value="false" />
</filter>
Perché non si configura un altro set di appenders nell'ambiente di test? –
Il metodo che stai provando richiede più che l'impostazione di threadName su TestRunnerThread, ma richiede anche qualcosa per impostare la proprietà log4net, ad esempio 'log4net.ThreadContext.Properties [" threadId "] =" TestRunnerThread ";' ed è improbabile che Nunit esegua fallo. – sgmoore
@WiktorZychla: questo sarà un autotest del programma. Alcuni test verificano se la configurazione è corretta. Sia la configurazione specifica del programma che log4net-config si trovano nello stesso file (app.config). Proverò a disabilitare le appenders dinamicamente in _self-test-mode_. – dirk