diff --git a/Plugins/Wox.Plugin.Program/Programs/UWP.cs b/Plugins/Wox.Plugin.Program/Programs/UWP.cs index eeb1b3cd80..ac6f416cb9 100644 --- a/Plugins/Wox.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Wox.Plugin.Program/Programs/UWP.cs @@ -363,9 +363,8 @@ namespace Wox.Plugin.Program.Programs // for // Microsoft.MicrosoftOfficeHub_17.7608.23501.0_x64__8wekyb3d8bbwe: ms-resource://Microsoft.MicrosoftOfficeHub/officehubintl/AppManifest_GetOffice_Description // Microsoft.BingFoodAndDrink_3.0.4.336_x64__8wekyb3d8bbwe: ms-resource:AppDescription - Log.Error($"Load {source} failed, HResult error code: {hResult}. Package location: <{Package.Location}>."); - var exception = Marshal.GetExceptionForHR((int)hResult); - Log.Exception(exception); + var e = Marshal.GetExceptionForHR((int)hResult); + Log.Error(e, $"Load {source} failed, HResult error code: {hResult}. Package location: <{Package.Location}>."); return string.Empty; } } diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 2859a1b3d8..e4ce5b070b 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; using NLog; using NLog.Config; using NLog.Targets; @@ -22,11 +23,13 @@ namespace Wox.Infrastructure.Logger var configuration = new LoggingConfiguration(); var target = new FileTarget(); configuration.AddTarget("file", target); - target.FileName = "${specialfolder:folder=ApplicationData}/" + Constant.Wox + "/" + DirectoryName + "/" + Constant.Version + "/${shortdate}.txt"; + target.FileName = "${specialfolder:folder=ApplicationData}/" + Constant.Wox + "/" + DirectoryName + "/" + + Constant.Version + "/${shortdate}.txt"; var rule = new LoggingRule("*", LogLevel.Info, target); configuration.LoggingRules.Add(rule); LogManager.Configuration = configuration; } + private static string CallerType() { var stackTrace = new StackTrace(); @@ -45,6 +48,24 @@ namespace Wox.Infrastructure.Logger logger.Error(msg); } + [MethodImpl(MethodImplOptions.Synchronized)] + public static void Error(System.Exception e, string msg) + { + var type = CallerType(); + var logger = LogManager.GetLogger(type); + System.Diagnostics.Debug.WriteLine($"ERROR: {msg}"); + logger.Error("-------------------------- Begin exception --------------------------"); + logger.Error(msg); + do + { + logger.Error($"Exception message:\n <{e.Message}>"); + logger.Error($"Exception stack trace:\n<{e.StackTrace}>"); + e = e.InnerException; + } while (e != null); + logger.Error("-------------------------- End exception --------------------------"); + } + + [MethodImpl(MethodImplOptions.Synchronized)] public static void Exception(System.Exception e) { var type = CallerType(); @@ -52,8 +73,8 @@ namespace Wox.Infrastructure.Logger do { - logger.Error(e.Message); - logger.Error($"\n{e.StackTrace}"); + logger.Error($"Exception message:\n <{e.Message}>"); + logger.Error($"Exception stack trace:\n<{e.StackTrace}>"); e = e.InnerException; } while (e != null); } @@ -93,4 +114,4 @@ namespace Wox.Infrastructure.Logger #endif } } -} +} \ No newline at end of file