Logging level can be set in the UI (immediately applied)

Logging level is set from config on startup as well
This commit is contained in:
Mark McDowall 2013-07-24 18:03:20 -07:00
parent 13b71bdeb7
commit 69d067d2c0
2 changed files with 51 additions and 2 deletions

View File

@ -31,13 +31,42 @@ namespace NzbDrone.Core.Instrumentation
public void Reconfigure()
{
var logLevel = _configFileProvider.LogLevel;
var minimumLogLevel = LogLevel.FromString(_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;
SetMinimumLogLevel(rollingFileLogger, minimumLogLevel);
}
private void SetMinimumLogLevel(LoggingRule rule, LogLevel minimumLogLevel)
{
foreach (var logLevel in GetLogLevels())
{
if (logLevel < minimumLogLevel)
{
rule.DisableLoggingForLevel(logLevel);
}
else
{
rule.EnableLoggingForLevel(logLevel);
}
}
}
private List<LogLevel> GetLogLevels()
{
return new List<LogLevel>
{
LogLevel.Trace,
LogLevel.Debug,
LogLevel.Info,
LogLevel.Warn,
LogLevel.Error,
LogLevel.Fatal
};
}
public void HandleAsync(ConfigFileSavedEvent message)

View File

@ -70,4 +70,24 @@
</div>
</div>
</fieldset>
<fieldset>
<legend>Logging</legend>
<div class="control-group">
<label class="control-label">Log Level</label>
<div class="controls">
<select name="logLevel">
<option value="Trace">Trace</option>
<option value="Debug">Debug</option>
<option value="Info">Info</option>
</select>
<span>
<i class="icon-form-danger" title="Trace and Debug logging should only be enabled temporarily"/>
</span>
</div>
</div>
</fieldset>
</div>