Write debug/trace log files separately to prevent trace from quickly rolling over debug.

pull/4/head
Taloth Saldono 9 years ago
parent a5077b0b1b
commit 59c68ec6cc

@ -102,26 +102,35 @@ namespace NzbDrone.Common.Instrumentation
const string FILE_LOG_LAYOUT = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"; const string FILE_LOG_LAYOUT = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}";
private static void RegisterAppFile(IAppFolderInfo appFolderInfo) private static void RegisterAppFile(IAppFolderInfo appFolderInfo)
{
RegisterAppFile(appFolderInfo, "appFileInfo", "sonarr.txt", 5);
RegisterAppFile(appFolderInfo, "appFileDebug", "sonarr.debug.txt", 50);
RegisterAppFile(appFolderInfo, "appFileTrace", "sonarr.trace.txt", 50);
}
private static LoggingRule RegisterAppFile(IAppFolderInfo appFolderInfo, string name, string fileName, int maxArchiveFiles)
{ {
var fileTarget = new NzbDroneFileTarget(); var fileTarget = new NzbDroneFileTarget();
fileTarget.Name = "rollingFileLogger"; fileTarget.Name = name;
fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), "nzbdrone.txt"); fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), fileName);
fileTarget.AutoFlush = true; fileTarget.AutoFlush = true;
fileTarget.KeepFileOpen = false; fileTarget.KeepFileOpen = false;
fileTarget.ConcurrentWrites = false; fileTarget.ConcurrentWrites = false;
fileTarget.ConcurrentWriteAttemptDelay = 50; fileTarget.ConcurrentWriteAttemptDelay = 50;
fileTarget.ConcurrentWriteAttempts = 10; fileTarget.ConcurrentWriteAttempts = 10;
fileTarget.ArchiveAboveSize = 1024000; fileTarget.ArchiveAboveSize = 1024000;
fileTarget.MaxArchiveFiles = 5; fileTarget.MaxArchiveFiles = maxArchiveFiles;
fileTarget.EnableFileDelete = true; fileTarget.EnableFileDelete = true;
fileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling; fileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling;
fileTarget.Layout = FILE_LOG_LAYOUT; fileTarget.Layout = FILE_LOG_LAYOUT;
var loggingRule = new LoggingRule("*", LogLevel.Trace, fileTarget); var loggingRule = new LoggingRule("*", LogLevel.Trace, fileTarget);
LogManager.Configuration.AddTarget("appfile", fileTarget); LogManager.Configuration.AddTarget(name, fileTarget);
LogManager.Configuration.LoggingRules.Add(loggingRule); LogManager.Configuration.LoggingRules.Add(loggingRule);
return loggingRule;
} }
private static void RegisterUpdateFile(IAppFolderInfo appFolderInfo) private static void RegisterUpdateFile(IAppFolderInfo appFolderInfo)

@ -28,24 +28,24 @@ namespace NzbDrone.Core.Instrumentation
var rules = LogManager.Configuration.LoggingRules; var rules = LogManager.Configuration.LoggingRules;
//Console //Console
var consoleLoggerRule = rules.SingleOrDefault(s => s.Targets.Any(t => t is ColoredConsoleTarget)); SetMinimumLogLevel(rules, "consoleLogger", minimumLogLevel);
if (consoleLoggerRule != null)
{
consoleLoggerRule.EnableLoggingForLevel(LogLevel.Trace);
SetMinimumLogLevel(consoleLoggerRule, minimumLogLevel);
}
//Log Files //Log Files
var rollingFileLoggerRule = rules.Single(s => s.Targets.Any(t => t is NzbDroneFileTarget)); SetMinimumLogLevel(rules, "appFileInfo", minimumLogLevel <= LogLevel.Info ? LogLevel.Info : LogLevel.Off);
rollingFileLoggerRule.EnableLoggingForLevel(LogLevel.Trace); SetMinimumLogLevel(rules, "appFileDebug", minimumLogLevel <= LogLevel.Debug ? LogLevel.Debug : LogLevel.Off);
SetMinimumLogLevel(rules, "appFileTrace", minimumLogLevel <= LogLevel.Trace ? LogLevel.Trace : LogLevel.Off);
SetMinimumLogLevel(rollingFileLoggerRule, minimumLogLevel);
SetMaxArchiveFiles(rollingFileLoggerRule, minimumLogLevel);
LogManager.ReconfigExistingLoggers(); LogManager.ReconfigExistingLoggers();
} }
private void SetMinimumLogLevel(IList<LoggingRule> rules, string target, LogLevel minimumLogLevel)
{
foreach (var rule in rules.Where(v => v.Targets.Any(t => t.Name == target)))
{
SetMinimumLogLevel(rule, minimumLogLevel);
}
}
private void SetMinimumLogLevel(LoggingRule rule, LogLevel minimumLogLevel) private void SetMinimumLogLevel(LoggingRule rule, LogLevel minimumLogLevel)
{ {
foreach (var logLevel in GetLogLevels()) foreach (var logLevel in GetLogLevels())
@ -62,23 +62,6 @@ namespace NzbDrone.Core.Instrumentation
} }
} }
private void SetMaxArchiveFiles(LoggingRule rule, LogLevel minimumLogLevel)
{
var target = rule.Targets.Single(t => t is NzbDroneFileTarget) as NzbDroneFileTarget;
if (target == null) return;
if (minimumLogLevel >= LogLevel.Info)
{
target.MaxArchiveFiles = 5;
}
else
{
target.MaxArchiveFiles = 50;
}
}
private List<LogLevel> GetLogLevels() private List<LogLevel> GetLogLevels()
{ {
return new List<LogLevel> return new List<LogLevel>

Loading…
Cancel
Save