From 0aeb9fdfbd562c0780dfc5c5b204fb451bde6ee3 Mon Sep 17 00:00:00 2001 From: Caelan Date: Tue, 7 Jun 2022 23:21:24 -0600 Subject: [PATCH] Show correct log path in error dialog --- src/Squirrel.CommandLine/ConsoleLogger.cs | 6 +++++- src/Update.Windows/Logging.cs | 6 +++++- src/Update.Windows/Program.cs | 10 ++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Squirrel.CommandLine/ConsoleLogger.cs b/src/Squirrel.CommandLine/ConsoleLogger.cs index 1aa8967e4..94ff3d51e 100644 --- a/src/Squirrel.CommandLine/ConsoleLogger.cs +++ b/src/Squirrel.CommandLine/ConsoleLogger.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Squirrel.SimpleSplat; namespace Squirrel.CommandLine @@ -10,6 +11,7 @@ class ConsoleLogger : ILogger private readonly object gate = new object(); private readonly string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + private readonly string localTemp = Path.GetTempPath(); public void Write(string message, LogLevel logLevel) { @@ -17,8 +19,10 @@ public void Write(string message, LogLevel logLevel) return; } - if (SquirrelRuntimeInfo.IsWindows) + if (SquirrelRuntimeInfo.IsWindows) { + message = message.Replace(localTemp, "%temp%", StringComparison.InvariantCultureIgnoreCase); message = message.Replace(localAppData, "%localappdata%", StringComparison.InvariantCultureIgnoreCase); + } lock (gate) { string lvl = logLevel.ToString().Substring(0, 4).ToUpper(); diff --git a/src/Update.Windows/Logging.cs b/src/Update.Windows/Logging.cs index 6c9122509..599cd598f 100644 --- a/src/Update.Windows/Logging.cs +++ b/src/Update.Windows/Logging.cs @@ -10,6 +10,8 @@ class SetupLogLogger : ILogger { public LogLevel Level { get; set; } = LogLevel.Info; + public string LogFilePath { get; } + private readonly NLog.Logger _log; public SetupLogLogger(UpdateAction action) @@ -27,11 +29,13 @@ public SetupLogLogger(UpdateAction action) : SquirrelRuntimeInfo.BaseDirectory; var logName = logToTemp ? "Squirrel.log" : $"Squirrel-{action}.log"; var logArchiveName = logToTemp ? "Squirrel.{###}.log" : $"Squirrel-{action}.{{###}}.log"; + + LogFilePath = Path.Combine(logDirectory, logName); // https://gist.github.com/chrisortman/1092889 SimpleConfigurator.ConfigureForTargetLogging( new FileTarget() { - FileName = Path.Combine(logDirectory, logName), + FileName = LogFilePath, Layout = new NLog.Layouts.SimpleLayout("${longdate} [${level:uppercase=true}] - ${message}"), ArchiveFileName = Path.Combine(logDirectory, logArchiveName), ArchiveAboveSize = 1_000_000, diff --git a/src/Update.Windows/Program.cs b/src/Update.Windows/Program.cs index d9794684d..49bf39682 100644 --- a/src/Update.Windows/Program.cs +++ b/src/Update.Windows/Program.cs @@ -21,7 +21,9 @@ namespace Squirrel.Update { class Program : IEnableLogger { - static StartupOption opt; + private static StartupOption opt; + private static SetupLogLogger _log; + static IFullLogger Log => SquirrelLocator.Current.GetService().GetLogger(typeof(Program)); [STAThread] @@ -42,8 +44,8 @@ static int main(string[] args) try { opt = new StartupOption(args); } catch (Exception ex) { - var logp = new SetupLogLogger(UpdateAction.Unset); - logp.Write($"Failed to parse command line options. {ex.Message}", LogLevel.Error); + _log = new SetupLogLogger(UpdateAction.Unset); + _log.Write($"Failed to parse command line options. {ex.Message}", LogLevel.Error); throw; } @@ -89,7 +91,7 @@ static int executeCommandLine(string[] args) Windows.User32MessageBox.Show( IntPtr.Zero, "Setup encountered fatal error: " + ex.Message + Environment.NewLine - + "There may be more detailed information in '%localappdata%\\SquirrelClowdTemp\\Squirrel.log'.", + + $"There may be more detailed information in '{_log.LogFilePath}'.", "Setup Error", Windows.User32MessageBox.MessageBoxButtons.OK, Windows.User32MessageBox.MessageBoxIcon.Error);