1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 20:42:37 +01:00
Radarr/NzbDrone.Test.Common/LoggingTest.cs

51 lines
1.7 KiB
C#
Raw Normal View History

2011-10-24 07:54:09 +02:00
using NLog;
using NLog.Config;
using NLog.Targets;
2011-11-13 08:27:16 +01:00
using NUnit.Framework;
2011-10-24 07:54:09 +02:00
using NzbDrone.Common;
namespace NzbDrone.Test.Common
{
public abstract class LoggingTest
2011-10-24 07:54:09 +02:00
{
2013-02-23 21:09:44 +01:00
protected Logger TestLogger = LogManager.GetLogger("TestLogger");
protected static void InitLogging()
2011-10-24 07:54:09 +02:00
{
2011-11-08 08:01:52 +01:00
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
{
LogManager.Configuration = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget { Layout = "${message} ${exception}" };
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, 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);
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-04-30 02:24:11 +02:00
if (TestContext.CurrentContext.Result.State == TestState.Failure || TestContext.CurrentContext.Result.State == TestState.Error)
2013-04-30 02:04:14 +02:00
{
ExceptionVerification.AssertNoUnexcpectedLogs();
}
2011-10-24 07:54:09 +02:00
}
}
}