From 84d6e8d121a1b329d26cc0e462aadd1108d99a04 Mon Sep 17 00:00:00 2001
From: jcm <john.moody@coloradocollege.edu>
Date: Sat, 10 Feb 2024 19:17:19 -0600
Subject: Standardize logging locations across desktop platforms (#6238)

* Standardize logging locations across desktop platforms

* Return null instead of empty literal on exceptions

* Remove LogDirectoryPath from LoggerModule

* Catch exception when creating DirectoryInfo in FileLogTarget

* Remove redundant log path vars, handle exception better, add null check

* Address styling issues

* Remove extra newline, quote file path in log, move directory check to OpenHelper

* Add GetOrCreateLogsDir to get/create log directory during runtime

* misc format changes

* Update src/Ryujinx.Common/Configuration/AppDataManager.cs

---------

Co-authored-by: jcm <butt@butts.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Ac_K <Acoustik666@gmail.com>
---
 .../Configuration/LoggerModule.cs                  | 24 ++++++++--------------
 1 file changed, 9 insertions(+), 15 deletions(-)

(limited to 'src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs')

diff --git a/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs b/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs
index f22ee83a..2edcd07f 100644
--- a/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs
+++ b/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs
@@ -9,8 +9,6 @@ namespace Ryujinx.Ui.Common.Configuration
 {
     public static class LoggerModule
     {
-        public static string LogDirectoryPath { get; private set; }
-
         public static void Initialize()
         {
             ConfigurationState.Instance.Logger.EnableDebug.Event += ReloadEnableDebug;
@@ -84,26 +82,22 @@ namespace Ryujinx.Ui.Common.Configuration
         {
             if (e.NewValue)
             {
-                string logDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
-                FileStream logFile = FileLogTarget.PrepareLogFile(logDir);
+                string logDir = AppDataManager.LogsDirPath;
+                FileStream logFile = null;
 
-                if (logFile == null)
+                if (!string.IsNullOrEmpty(logDir))
                 {
-                    logDir = Path.Combine(AppDataManager.BaseDirPath, "Logs");
                     logFile = FileLogTarget.PrepareLogFile(logDir);
+                }
 
-                    if (logFile == null)
-                    {
-                        Logger.Error?.Print(LogClass.Application, "No writable log directory available. Make sure either the application directory or the Ryujinx directory is writable.");
-                        LogDirectoryPath = null;
-                        Logger.RemoveTarget("file");
+                if (logFile == null)
+                {
+                    Logger.Error?.Print(LogClass.Application, "No writable log directory available. Make sure either the Logs directory, Application Data, or the Ryujinx directory is writable.");
+                    Logger.RemoveTarget("file");
 
-                        return;
-                    }
+                    return;
                 }
 
-                LogDirectoryPath = logDir;
-
                 Logger.AddTarget(new AsyncLogTargetWrapper(
                     new FileLogTarget("file", logFile),
                     1000,
-- 
cgit v1.2.3-70-g09d2