From 505f95848ba28a59893b574dba1c5a50af63e60a Mon Sep 17 00:00:00 2001 From: BaronKiko Date: Wed, 12 Feb 2020 01:18:33 +0000 Subject: [PATCH] Reducing log sizes (#724) * Separated out log's into a separate file for each run. It will keep up to 3 * Rebase part 2 Co-authored-by: Andy Adshead --- Ryujinx.Common/Configuration/LoggerModule.cs | 2 +- Ryujinx.Common/Logging/Targets/FileLogTarget.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Ryujinx.Common/Configuration/LoggerModule.cs b/Ryujinx.Common/Configuration/LoggerModule.cs index 504a8141..058bea5b 100644 --- a/Ryujinx.Common/Configuration/LoggerModule.cs +++ b/Ryujinx.Common/Configuration/LoggerModule.cs @@ -78,7 +78,7 @@ namespace Ryujinx.Configuration if (e.NewValue) { Logger.AddTarget(new AsyncLogTargetWrapper( - new FileLogTarget(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx.log"), "file"), + new FileLogTarget(AppDomain.CurrentDomain.BaseDirectory, "file"), 1000, AsyncLogTargetOverflowAction.Block )); diff --git a/Ryujinx.Common/Logging/Targets/FileLogTarget.cs b/Ryujinx.Common/Logging/Targets/FileLogTarget.cs index 4db5f7bc..46fffd3a 100644 --- a/Ryujinx.Common/Logging/Targets/FileLogTarget.cs +++ b/Ryujinx.Common/Logging/Targets/FileLogTarget.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Text; namespace Ryujinx.Common.Logging @@ -20,6 +21,20 @@ namespace Ryujinx.Common.Logging public FileLogTarget(string path, string name, FileShare fileShare, FileMode fileMode) { + // Ensure directory is present + DirectoryInfo logDir = new DirectoryInfo(Path.Combine(path, "Logs")); + logDir.Create(); + + // Clean up old logs, should only keep 3 + FileInfo[] files = logDir.GetFiles("*.log").OrderBy((info => info.CreationTime)).ToArray(); + for (int i = 0; i < files.Length - 2; i++) + { + files[i].Delete(); + } + + // Get path for the current time + path = Path.Combine(logDir.FullName, $"Ryujinx_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.log"); + _name = name; _logWriter = new StreamWriter(File.Open(path, fileMode, FileAccess.Write, fileShare)); _formatter = new DefaultLogFormatter();