From 7ad1e413d2dd29a30561f07d43139bb99ac9bd1c Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Sat, 8 Jun 2024 18:30:59 +0100 Subject: [PATCH 1/2] Logger will not try and resolve path if not logging to disk --- Core/Core/Logging/SpeckleLog.cs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Core/Core/Logging/SpeckleLog.cs b/Core/Core/Logging/SpeckleLog.cs index fba2ac094f..7d22ebe971 100644 --- a/Core/Core/Logging/SpeckleLog.cs +++ b/Core/Core/Logging/SpeckleLog.cs @@ -173,13 +173,6 @@ public static Logger CreateConfiguredLogger( SpeckleLogConfiguration logConfiguration ) { - // TODO: check if we have write permissions to the file. - // if not, disable file sink, even if its enabled in the config - // show a warning about that... - var canLogToFile = true; - s_logFolderPath = SpecklePathProvider.LogFolderPath(hostApplicationName, hostApplicationVersion); - var logFilePath = Path.Combine(s_logFolderPath, "SpeckleCoreLog.txt"); - var fileVersionInfo = GetFileVersionInfo(); var serilogLogConfiguration = new LoggerConfiguration().MinimumLevel .Is(logConfiguration.MinimumLevel) @@ -200,8 +193,21 @@ SpeckleLogConfiguration logConfiguration .Enrich.WithExceptionDetails(); } - if (logConfiguration.LogToFile && canLogToFile) + if (logConfiguration.LogToFile) { + // TODO: check if we have write permissions to the file. + // if not, disable file sink, even if its enabled in the config + // show a warning about that... + // if (!canLogToFile) + // { + // logger.Warning("Log to file is enabled, but cannot write to {LogFilePath}", logFilePath); + // } + // else + // { + + s_logFolderPath = SpecklePathProvider.LogFolderPath(hostApplicationName, hostApplicationVersion); + var logFilePath = Path.Combine(s_logFolderPath, "SpeckleCoreLog.txt"); + serilogLogConfiguration = serilogLogConfiguration.WriteTo.File( logFilePath, rollingInterval: RollingInterval.Day, @@ -253,10 +259,6 @@ SpeckleLogConfiguration logConfiguration var logger = serilogLogConfiguration.CreateLogger(); - if (logConfiguration.LogToFile && !canLogToFile) - { - logger.Warning("Log to file is enabled, but cannot write to {LogFilePath}", logFilePath); - } if (s_isMachineIdUsed) { From 76b71d7601ea49daf26d443a4b0bbae84699d56f Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Sat, 8 Jun 2024 18:39:29 +0100 Subject: [PATCH 2/2] formatting --- Core/Core/Logging/SpeckleLog.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/Core/Logging/SpeckleLog.cs b/Core/Core/Logging/SpeckleLog.cs index 7d22ebe971..1e893171bb 100644 --- a/Core/Core/Logging/SpeckleLog.cs +++ b/Core/Core/Logging/SpeckleLog.cs @@ -204,7 +204,7 @@ SpeckleLogConfiguration logConfiguration // } // else // { - + s_logFolderPath = SpecklePathProvider.LogFolderPath(hostApplicationName, hostApplicationVersion); var logFilePath = Path.Combine(s_logFolderPath, "SpeckleCoreLog.txt"); @@ -259,7 +259,6 @@ SpeckleLogConfiguration logConfiguration var logger = serilogLogConfiguration.CreateLogger(); - if (s_isMachineIdUsed) { logger.Warning("Cannot set user id for the global log context.");