Log level halfway there

pull/4/head
Mark McDowall 12 years ago
parent f162c5848f
commit 84af2be14a

@ -10,6 +10,7 @@ namespace NzbDrone.Common
private const string NZBDRONE_DB = "nzbdrone.db"; private const string NZBDRONE_DB = "nzbdrone.db";
private const string NZBDRONE_LOG_DB = "logs.db"; private const string NZBDRONE_LOG_DB = "logs.db";
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip"; private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private const string NLOG_CONFIG_FILE = "nlog.config";
private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar; private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone" + Path.DirectorySeparatorChar; private static readonly string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone" + Path.DirectorySeparatorChar;
@ -70,7 +71,6 @@ namespace NzbDrone.Common
return Path.Combine(GetProperCapitalization(dirInfo), dirInfo.GetFiles(fileInfo.Name)[0].Name); return Path.Combine(GetProperCapitalization(dirInfo), dirInfo.GetFiles(fileInfo.Name)[0].Name);
} }
public static string GetAppDataPath(this IAppFolderInfo appFolderInfo) public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
{ {
return appFolderInfo.AppDataFolder; return appFolderInfo.AppDataFolder;
@ -135,5 +135,10 @@ namespace NzbDrone.Common
{ {
return Path.Combine(GetAppDataPath(appFolderInfo), NZBDRONE_LOG_DB); return Path.Combine(GetAppDataPath(appFolderInfo), NZBDRONE_LOG_DB);
} }
public static string GetNlogConfigPath(this IAppFolderInfo appFolderInfo)
{
return Path.Combine(appFolderInfo.StartUpFolder, NLOG_CONFIG_FILE);
}
} }
} }

@ -6,6 +6,8 @@ using System.Xml.Linq;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Configuration.Events;
namespace NzbDrone.Core.Configuration namespace NzbDrone.Core.Configuration
{ {
@ -19,19 +21,22 @@ namespace NzbDrone.Core.Configuration
bool AuthenticationEnabled { get; } bool AuthenticationEnabled { get; }
string Username { get; } string Username { get; }
string Password { get; } string Password { get; }
string LogLevel { get; }
} }
public class ConfigFileProvider : IConfigFileProvider public class ConfigFileProvider : IConfigFileProvider
{ {
private readonly IAppFolderInfo _appFolderInfo; private readonly IAppFolderInfo _appFolderInfo;
private readonly IMessageAggregator _messageAggregator;
private readonly ICached<string> _cache; private readonly ICached<string> _cache;
private readonly string _configFile; private readonly string _configFile;
public ConfigFileProvider(IAppFolderInfo appFolderInfo, ICacheManger cacheManger) public ConfigFileProvider(IAppFolderInfo appFolderInfo, ICacheManger cacheManger, IMessageAggregator messageAggregator)
{ {
_appFolderInfo = appFolderInfo; _appFolderInfo = appFolderInfo;
_cache = cacheManger.GetCache<string>(GetType()); _cache = cacheManger.GetCache<string>(GetType());
_messageAggregator = messageAggregator;
_configFile = _appFolderInfo.GetConfigPath(); _configFile = _appFolderInfo.GetConfigPath();
} }
@ -72,7 +77,7 @@ namespace NzbDrone.Core.Configuration
} }
} }
_messageAggregator.PublishEvent(new ConfigFileSavedEvent());
} }
public int Port public int Port
@ -100,6 +105,11 @@ namespace NzbDrone.Core.Configuration
get { return GetValue("Password", ""); } get { return GetValue("Password", ""); }
} }
public string LogLevel
{
get { return GetValue("LogLevel", "Info"); }
}
public int GetValueInt(string key, int defaultValue) public int GetValueInt(string key, int defaultValue)
{ {
return Convert.ToInt32(GetValue(key, defaultValue)); return Convert.ToInt32(GetValue(key, defaultValue));

@ -5,6 +5,7 @@ using NLog;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Download.Clients.Sabnzbd; using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Instrumentation;
namespace NzbDrone.Core.Configuration namespace NzbDrone.Core.Configuration
{ {

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Configuration.Events
{
public class ConfigFileSavedEvent : IEvent
{
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Download.Clients.Sabnzbd; using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Instrumentation;
namespace NzbDrone.Core.Configuration namespace NzbDrone.Core.Configuration
{ {

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using NLog;
using NLog.Config;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Core.Instrumentation
{
public interface ISetLoggingLevel
{
void Reconfigure();
}
public class SetLoggingLevel : ISetLoggingLevel, IHandleAsync<ConfigFileSavedEvent>, IHandleAsync<ApplicationStartedEvent>
{
private readonly IConfigFileProvider _configFileProvider;
public SetLoggingLevel(IConfigFileProvider configFileProvider)
{
_configFileProvider = configFileProvider;
}
public void Reconfigure()
{
var logLevel = _configFileProvider.LogLevel;
var rules = LogManager.Configuration.LoggingRules;
var rollingFileLogger = rules.Single(s => s.Targets.Any(t => t.Name == "rollingFileLogger"));
rollingFileLogger.EnableLoggingForLevel(LogLevel.Trace);
var test = 1;
}
public void HandleAsync(ConfigFileSavedEvent message)
{
Reconfigure();
}
public void HandleAsync(ApplicationStartedEvent message)
{
Reconfigure();
}
}
}

@ -180,6 +180,7 @@
<Compile Include="Configuration\Config.cs" /> <Compile Include="Configuration\Config.cs" />
<Compile Include="Configuration\ConfigFileProvider.cs" /> <Compile Include="Configuration\ConfigFileProvider.cs" />
<Compile Include="Configuration\ConfigRepository.cs" /> <Compile Include="Configuration\ConfigRepository.cs" />
<Compile Include="Configuration\Events\ConfigFileSavedEvent.cs" />
<Compile Include="Configuration\IConfigService.cs" /> <Compile Include="Configuration\IConfigService.cs" />
<Compile Include="DataAugmentation\DailySeries\DailySeriesDataProxy.cs" /> <Compile Include="DataAugmentation\DailySeries\DailySeriesDataProxy.cs" />
<Compile Include="DataAugmentation\DailySeries\DailySeriesService.cs" /> <Compile Include="DataAugmentation\DailySeries\DailySeriesService.cs" />
@ -268,6 +269,7 @@
<Compile Include="Indexers\IndexerWithSetting.cs" /> <Compile Include="Indexers\IndexerWithSetting.cs" />
<Compile Include="Indexers\RssSyncCommand.cs" /> <Compile Include="Indexers\RssSyncCommand.cs" />
<Compile Include="Instrumentation\Commands\TrimLogCommand.cs" /> <Compile Include="Instrumentation\Commands\TrimLogCommand.cs" />
<Compile Include="Instrumentation\SetLoggingLevel.cs" />
<Compile Include="Jobs\TaskManager.cs" /> <Compile Include="Jobs\TaskManager.cs" />
<Compile Include="Lifecycle\ApplicationShutdownRequested.cs" /> <Compile Include="Lifecycle\ApplicationShutdownRequested.cs" />
<Compile Include="MediaCover\CoverAlreadyExistsSpecification.cs" /> <Compile Include="MediaCover\CoverAlreadyExistsSpecification.cs" />

Loading…
Cancel
Save