mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
enhance exception logging
This commit is contained in:
@@ -363,9 +363,8 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
// for
|
// for
|
||||||
// Microsoft.MicrosoftOfficeHub_17.7608.23501.0_x64__8wekyb3d8bbwe: ms-resource://Microsoft.MicrosoftOfficeHub/officehubintl/AppManifest_GetOffice_Description
|
// 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
|
// 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 e = Marshal.GetExceptionForHR((int)hResult);
|
||||||
var exception = Marshal.GetExceptionForHR((int)hResult);
|
Log.Error(e, $"Load {source} failed, HResult error code: {hResult}. Package location: <{Package.Location}>.");
|
||||||
Log.Exception(exception);
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
@@ -22,11 +23,13 @@ namespace Wox.Infrastructure.Logger
|
|||||||
var configuration = new LoggingConfiguration();
|
var configuration = new LoggingConfiguration();
|
||||||
var target = new FileTarget();
|
var target = new FileTarget();
|
||||||
configuration.AddTarget("file", target);
|
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);
|
var rule = new LoggingRule("*", LogLevel.Info, target);
|
||||||
configuration.LoggingRules.Add(rule);
|
configuration.LoggingRules.Add(rule);
|
||||||
LogManager.Configuration = configuration;
|
LogManager.Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CallerType()
|
private static string CallerType()
|
||||||
{
|
{
|
||||||
var stackTrace = new StackTrace();
|
var stackTrace = new StackTrace();
|
||||||
@@ -45,6 +48,24 @@ namespace Wox.Infrastructure.Logger
|
|||||||
logger.Error(msg);
|
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)
|
public static void Exception(System.Exception e)
|
||||||
{
|
{
|
||||||
var type = CallerType();
|
var type = CallerType();
|
||||||
@@ -52,8 +73,8 @@ namespace Wox.Infrastructure.Logger
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
logger.Error(e.Message);
|
logger.Error($"Exception message:\n <{e.Message}>");
|
||||||
logger.Error($"\n{e.StackTrace}");
|
logger.Error($"Exception stack trace:\n<{e.StackTrace}>");
|
||||||
e = e.InnerException;
|
e = e.InnerException;
|
||||||
} while (e != null);
|
} while (e != null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user