2011-10-24 05:54:09 +00:00
|
|
|
using NLog;
|
|
|
|
using NLog.Config;
|
2013-02-28 02:43:01 +00:00
|
|
|
using NLog.Targets;
|
2011-11-13 07:27:16 +00:00
|
|
|
using NUnit.Framework;
|
2011-10-24 05:54:09 +00:00
|
|
|
using NzbDrone.Common;
|
|
|
|
|
|
|
|
namespace NzbDrone.Test.Common
|
|
|
|
{
|
2011-11-03 05:04:14 +00:00
|
|
|
public abstract class LoggingTest
|
2011-10-24 05:54:09 +00:00
|
|
|
{
|
2013-02-23 20:09:44 +00:00
|
|
|
|
|
|
|
protected Logger TestLogger = LogManager.GetLogger("TestLogger");
|
|
|
|
|
2011-11-03 05:04:14 +00:00
|
|
|
protected static void InitLogging()
|
2011-10-24 05:54:09 +00:00
|
|
|
{
|
2011-11-08 07:01:52 +00:00
|
|
|
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
|
|
|
{
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
2013-03-04 05:53:02 +00:00
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${message} ${exception}" };
|
2013-02-28 02:43:01 +00:00
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
2013-03-04 05:53:02 +00:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
2011-10-24 05:54:09 +00:00
|
|
|
|
2011-11-08 07:01:52 +00:00
|
|
|
RegisterExceptionVerification();
|
|
|
|
}
|
2011-10-24 05:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void RegisterExceptionVerification()
|
|
|
|
{
|
|
|
|
var exceptionVerification = new ExceptionVerification();
|
|
|
|
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
|
2013-03-04 05:53:02 +00:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, exceptionVerification));
|
2011-11-13 07:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void LoggingTestSetup()
|
|
|
|
{
|
|
|
|
InitLogging();
|
|
|
|
ExceptionVerification.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void LoggingDownBase()
|
|
|
|
{
|
2013-04-30 00:39:25 +00:00
|
|
|
|
|
|
|
//if (TestContext.CurrentContext.Result.State == TestState.Failure || TestContext.CurrentContext.Result.State == TestState.Error)
|
2013-04-30 00:04:14 +00:00
|
|
|
{
|
|
|
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
|
|
|
}
|
2011-10-24 05:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|