mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Write debug/trace log files separately to prevent trace from quickly rolling over debug.
This commit is contained in:
parent
a5077b0b1b
commit
59c68ec6cc
@ -102,26 +102,35 @@ private static void RegisterConsole()
|
||||
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)
|
||||
{
|
||||
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();
|
||||
|
||||
fileTarget.Name = "rollingFileLogger";
|
||||
fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), "nzbdrone.txt");
|
||||
fileTarget.Name = name;
|
||||
fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), fileName);
|
||||
fileTarget.AutoFlush = true;
|
||||
fileTarget.KeepFileOpen = false;
|
||||
fileTarget.ConcurrentWrites = false;
|
||||
fileTarget.ConcurrentWriteAttemptDelay = 50;
|
||||
fileTarget.ConcurrentWriteAttempts = 10;
|
||||
fileTarget.ArchiveAboveSize = 1024000;
|
||||
fileTarget.MaxArchiveFiles = 5;
|
||||
fileTarget.MaxArchiveFiles = maxArchiveFiles;
|
||||
fileTarget.EnableFileDelete = true;
|
||||
fileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling;
|
||||
fileTarget.Layout = FILE_LOG_LAYOUT;
|
||||
|
||||
var loggingRule = new LoggingRule("*", LogLevel.Trace, fileTarget);
|
||||
|
||||
LogManager.Configuration.AddTarget("appfile", fileTarget);
|
||||
LogManager.Configuration.AddTarget(name, fileTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(loggingRule);
|
||||
|
||||
return loggingRule;
|
||||
}
|
||||
|
||||
private static void RegisterUpdateFile(IAppFolderInfo appFolderInfo)
|
||||
|
@ -28,24 +28,24 @@ public void Reconfigure()
|
||||
var rules = LogManager.Configuration.LoggingRules;
|
||||
|
||||
//Console
|
||||
var consoleLoggerRule = rules.SingleOrDefault(s => s.Targets.Any(t => t is ColoredConsoleTarget));
|
||||
|
||||
if (consoleLoggerRule != null)
|
||||
{
|
||||
consoleLoggerRule.EnableLoggingForLevel(LogLevel.Trace);
|
||||
SetMinimumLogLevel(consoleLoggerRule, minimumLogLevel);
|
||||
}
|
||||
SetMinimumLogLevel(rules, "consoleLogger", minimumLogLevel);
|
||||
|
||||
//Log Files
|
||||
var rollingFileLoggerRule = rules.Single(s => s.Targets.Any(t => t is NzbDroneFileTarget));
|
||||
rollingFileLoggerRule.EnableLoggingForLevel(LogLevel.Trace);
|
||||
|
||||
SetMinimumLogLevel(rollingFileLoggerRule, minimumLogLevel);
|
||||
SetMaxArchiveFiles(rollingFileLoggerRule, minimumLogLevel);
|
||||
SetMinimumLogLevel(rules, "appFileInfo", minimumLogLevel <= LogLevel.Info ? LogLevel.Info : LogLevel.Off);
|
||||
SetMinimumLogLevel(rules, "appFileDebug", minimumLogLevel <= LogLevel.Debug ? LogLevel.Debug : LogLevel.Off);
|
||||
SetMinimumLogLevel(rules, "appFileTrace", minimumLogLevel <= LogLevel.Trace ? LogLevel.Trace : LogLevel.Off);
|
||||
|
||||
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)
|
||||
{
|
||||
foreach (var logLevel in GetLogLevels())
|
||||
@ -62,23 +62,6 @@ private void SetMinimumLogLevel(LoggingRule rule, LogLevel minimumLogLevel)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return new List<LogLevel>
|
||||
|
Loading…
Reference in New Issue
Block a user