mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
DB log target is removed after test/app shutdown
This commit is contained in:
parent
c80202bec3
commit
c48ce4d9e0
@ -109,6 +109,13 @@ public void null_string_as_arg_should_not_fail()
|
|||||||
epFile.Path.Should().BeNull();
|
epFile.Path.Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TearDown]
|
||||||
|
public void Teardown()
|
||||||
|
{
|
||||||
|
Mocker.Resolve<DatabaseTarget>().UnRegister();
|
||||||
|
}
|
||||||
|
|
||||||
private void VerifyLog(Log logItem, LogLevel level)
|
private void VerifyLog(Log logItem, LogLevel level)
|
||||||
{
|
{
|
||||||
logItem.Time.Should().BeWithin(TimeSpan.FromSeconds(2));
|
logItem.Time.Should().BeWithin(TimeSpan.FromSeconds(2));
|
||||||
|
@ -3,11 +3,13 @@
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Layouts;
|
using NLog.Layouts;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
using NzbDrone.Core.Lifecycle;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Instrumentation
|
namespace NzbDrone.Core.Instrumentation
|
||||||
{
|
{
|
||||||
|
|
||||||
public class DatabaseTarget : TargetWithLayout
|
public class DatabaseTarget : TargetWithLayout, IHandle<ApplicationShutdownRequested>
|
||||||
{
|
{
|
||||||
private readonly ILogRepository _repository;
|
private readonly ILogRepository _repository;
|
||||||
|
|
||||||
@ -24,10 +26,23 @@ public void Register()
|
|||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", this);
|
LogManager.Configuration.AddTarget("DbLogger", this);
|
||||||
LogManager.Configuration.LoggingRules.Add(Rule);
|
LogManager.Configuration.LoggingRules.Add(Rule);
|
||||||
LogManager.ConfigurationReloaded += (sender, args) => Register();
|
LogManager.ConfigurationReloaded += OnLogManagerOnConfigurationReloaded;
|
||||||
LogManager.ReconfigExistingLoggers();
|
LogManager.ReconfigExistingLoggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UnRegister()
|
||||||
|
{
|
||||||
|
LogManager.ConfigurationReloaded -= OnLogManagerOnConfigurationReloaded;
|
||||||
|
LogManager.Configuration.RemoveTarget("DbLogger");
|
||||||
|
LogManager.Configuration.LoggingRules.Remove(Rule);
|
||||||
|
LogManager.ReconfigExistingLoggers();
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLogManagerOnConfigurationReloaded(object sender, LoggingConfigurationReloadedEventArgs args)
|
||||||
|
{
|
||||||
|
Register();
|
||||||
|
}
|
||||||
|
|
||||||
public LoggingRule Rule { get; set; }
|
public LoggingRule Rule { get; set; }
|
||||||
|
|
||||||
@ -66,5 +81,13 @@ protected override void Write(LogEventInfo logEvent)
|
|||||||
|
|
||||||
_repository.Insert(log);
|
_repository.Insert(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Handle(ApplicationShutdownRequested message)
|
||||||
|
{
|
||||||
|
if (LogManager.Configuration.LoggingRules.Contains(Rule))
|
||||||
|
{
|
||||||
|
UnRegister();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user