1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-03-04 02:18:06 +00:00
Lidarr/NzbDrone.Test.Common/LoggingTest.cs

50 lines
1.6 KiB
C#
Raw Normal View History

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