2011-10-24 07:54:09 +02:00
|
|
|
using NLog;
|
|
|
|
using NLog.Config;
|
2013-02-28 03:43:01 +01:00
|
|
|
using NLog.Targets;
|
2011-11-13 08:27:16 +01:00
|
|
|
using NUnit.Framework;
|
2013-08-13 07:08:37 +02:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2011-10-24 07:54:09 +02:00
|
|
|
|
|
|
|
namespace NzbDrone.Test.Common
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
public abstract class LoggingTest
|
2011-10-24 07:54:09 +02:00
|
|
|
{
|
2013-08-13 07:08:37 +02:00
|
|
|
protected static Logger TestLogger;
|
2013-02-23 21:09:44 +01:00
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
protected static void InitLogging()
|
2011-10-24 07:54:09 +02:00
|
|
|
{
|
2013-08-13 07:08:37 +02:00
|
|
|
new StartupArguments();
|
|
|
|
|
|
|
|
TestLogger = LogManager.GetLogger("TestLogger");
|
|
|
|
|
2011-11-08 08:01:52 +01:00
|
|
|
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
|
|
|
{
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
2013-05-21 07:12:11 +02:00
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
|
2013-02-28 03:43:01 +01:00
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
2013-05-21 07:12:11 +02:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget));
|
2011-10-24 07:54:09 +02:00
|
|
|
|
2011-11-08 08:01:52 +01:00
|
|
|
RegisterExceptionVerification();
|
|
|
|
}
|
2011-10-24 07:54:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void RegisterExceptionVerification()
|
|
|
|
{
|
|
|
|
var exceptionVerification = new ExceptionVerification();
|
|
|
|
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
|
2013-03-04 06:53:02 +01:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, exceptionVerification));
|
2011-11-13 08:27:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void LoggingTestSetup()
|
|
|
|
{
|
|
|
|
InitLogging();
|
|
|
|
ExceptionVerification.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void LoggingDownBase()
|
|
|
|
{
|
2013-08-06 07:29:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
//can't use because of a bug in mono with 2.6.2,
|
|
|
|
//https://bugs.launchpad.net/nunitv2/+bug/1076932
|
2013-08-18 02:17:37 +02:00
|
|
|
if (OsInfo.IsWindows && TestContext.CurrentContext.Result.State == TestState.Success)
|
2013-04-30 02:04:14 +02:00
|
|
|
{
|
|
|
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
|
|
|
}
|
2011-10-24 07:54:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|