You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
13 years ago
|
using NLog;
|
||
|
using NLog.Config;
|
||
12 years ago
|
using NLog.Targets;
|
||
13 years ago
|
using NUnit.Framework;
|
||
11 years ago
|
using NzbDrone.Common.EnvironmentInfo;
|
||
13 years ago
|
|
||
|
namespace NzbDrone.Test.Common
|
||
|
{
|
||
13 years ago
|
public abstract class LoggingTest
|
||
13 years ago
|
{
|
||
11 years ago
|
protected static Logger TestLogger;
|
||
12 years ago
|
|
||
13 years ago
|
protected static void InitLogging()
|
||
13 years ago
|
{
|
||
11 years ago
|
new StartupArguments();
|
||
|
|
||
|
TestLogger = LogManager.GetLogger("TestLogger");
|
||
|
|
||
13 years ago
|
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
||
|
{
|
||
|
LogManager.Configuration = new LoggingConfiguration();
|
||
12 years ago
|
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
|
||
12 years ago
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
||
12 years ago
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget));
|
||
13 years ago
|
|
||
13 years ago
|
RegisterExceptionVerification();
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
|
private static void RegisterExceptionVerification()
|
||
|
{
|
||
|
var exceptionVerification = new ExceptionVerification();
|
||
|
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
|
||
12 years ago
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, exceptionVerification));
|
||
13 years ago
|
}
|
||
|
|
||
|
[SetUp]
|
||
|
public void LoggingTestSetup()
|
||
|
{
|
||
|
InitLogging();
|
||
|
ExceptionVerification.Reset();
|
||
|
}
|
||
|
|
||
|
[TearDown]
|
||
|
public void LoggingDownBase()
|
||
|
{
|
||
11 years ago
|
|
||
|
|
||
|
//can't use because of a bug in mono with 2.6.2,
|
||
|
//https://bugs.launchpad.net/nunitv2/+bug/1076932
|
||
11 years ago
|
if (BuildInfo.IsDebug && TestContext.CurrentContext.Result.State == TestState.Success)
|
||
12 years ago
|
{
|
||
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
||
|
}
|
||
13 years ago
|
}
|
||
|
}
|
||
|
}
|