mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Show correct log path in error dialog
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Squirrel.SimpleSplat;
|
||||
|
||||
namespace Squirrel.CommandLine
|
||||
@@ -10,6 +11,7 @@ namespace Squirrel.CommandLine
|
||||
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 @@ namespace Squirrel.CommandLine
|
||||
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();
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Squirrel.Update
|
||||
{
|
||||
public LogLevel Level { get; set; } = LogLevel.Info;
|
||||
|
||||
public string LogFilePath { get; }
|
||||
|
||||
private readonly NLog.Logger _log;
|
||||
|
||||
public SetupLogLogger(UpdateAction action)
|
||||
@@ -27,11 +29,13 @@ namespace Squirrel.Update
|
||||
: 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,
|
||||
|
||||
@@ -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<ILogManager>().GetLogger(typeof(Program));
|
||||
|
||||
[STAThread]
|
||||
@@ -42,8 +44,8 @@ namespace Squirrel.Update
|
||||
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 @@ namespace Squirrel.Update
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user