mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Improve logging for PT Run (#6800)
* init code pass * adjusting tabbing for readabilty * few small adjustments
This commit is contained in:
@@ -51,7 +51,7 @@ namespace Microsoft.Plugin.Calculator
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
#pragma warning restore CA1031 // Do not catch general exception types
|
#pragma warning restore CA1031 // Do not catch general exception types
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Calculator.Main.Query|Exception when query for <{query}>", e);
|
Log.Exception("Exception when query for <{query}>", e, GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<Result>();
|
return new List<Result>();
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Microsoft.Plugin.Folder
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var message = Properties.Resources.Microsoft_plugin_folder_clipboard_failed;
|
var message = Properties.Resources.Microsoft_plugin_folder_clipboard_failed;
|
||||||
LogException(message, e);
|
Log.Exception(message, e, GetType());
|
||||||
_context.API.ShowMsg(message);
|
_context.API.ShowMsg(message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,8 @@ namespace Microsoft.Plugin.Folder
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenuLoader.LoadContextMenus| Failed to open {record.FullPath} in console, {e.Message}", e);
|
Log.Exception($"Failed to open {record.FullPath} in console, {e.Message}", e, GetType());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -117,8 +118,9 @@ namespace Microsoft.Plugin.Folder
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var message = $"{Properties.Resources.Microsoft_plugin_folder_file_open_failed} {record.FullPath}";
|
var message = $"{Properties.Resources.Microsoft_plugin_folder_file_open_failed} {record.FullPath}";
|
||||||
LogException(message, e);
|
Log.Exception(message, e, GetType());
|
||||||
_context.API.ShowMsg(message);
|
_context.API.ShowMsg(message);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,11 +128,6 @@ namespace Microsoft.Plugin.Folder
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogException(string message, Exception e)
|
|
||||||
{
|
|
||||||
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenu|{message}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ResultType
|
public enum ResultType
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Diagnostics;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -120,7 +121,7 @@ namespace Microsoft.Plugin.Folder
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
string messageBoxTitle = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path);
|
string messageBoxTitle = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path);
|
||||||
Log.Exception($"|Microsoft.Plugin.Folder.Main.OpenFileOrFolder| Failed to open {path} in explorer, {e.Message}", e);
|
Log.Exception($"Failed to open {path} in explorer, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
_context.API.ShowMsg(messageBoxTitle, e.Message);
|
_context.API.ShowMsg(messageBoxTitle, e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var message = Properties.Resources.Microsoft_plugin_indexer_clipboard_failed;
|
var message = Properties.Resources.Microsoft_plugin_indexer_clipboard_failed;
|
||||||
LogException(message, e);
|
Log.Exception(message, e, GetType());
|
||||||
|
|
||||||
_context.API.ShowMsg(message);
|
_context.API.ShowMsg(message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -105,7 +106,7 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Indexer.ContextMenuLoader.LoadContextMenus| Failed to open {record.Path} in console, {e.Message}", e);
|
Log.Exception($"Failed to open {record.Path} in console, {e.Message}", e, GetType());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -136,7 +137,7 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Indexer.ContextMenu| Failed to run {record.Path} as admin, {e.Message}", e);
|
Log.Exception($"Failed to run {record.Path} as admin, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -178,7 +179,8 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var message = $"{Properties.Resources.Microsoft_plugin_indexer_folder_open_failed} {record.Path}";
|
var message = $"{Properties.Resources.Microsoft_plugin_indexer_folder_open_failed} {record.Path}";
|
||||||
LogException(message, e);
|
Log.Exception(message, e, GetType());
|
||||||
|
|
||||||
_context.API.ShowMsg(message);
|
_context.API.ShowMsg(message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -187,10 +189,5 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogException(string message, Exception e)
|
|
||||||
{
|
|
||||||
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenu|{message}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query");
|
Log.Exception($"Unable to launch Windows Search Settings: {ex.Message}", ex, GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -163,7 +163,7 @@ namespace Microsoft.Plugin.Indexer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Info(ex.ToString());
|
Log.Exception("Something failed", ex, GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,51 +22,29 @@ namespace Microsoft.Plugin.Program.Logger
|
|||||||
/// Logs an exception
|
/// Logs an exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
internal static void LogException(string classname, string callingMethodName, string loadingProgramPath, string interpretationMessage, Exception e)
|
internal static void Exception(string message, Exception ex, Type fullClassName, string loadingProgramPath, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"ERROR{classname}|{callingMethodName}|{loadingProgramPath}|{interpretationMessage}");
|
// internal static void LogException(string classname, string callingMethodName, string loadingProgramPath, string interpretationMessage, Exception e)
|
||||||
|
|
||||||
var possibleResolution = "Not yet known";
|
var possibleResolution = "Not yet known";
|
||||||
var errorStatus = "UNKNOWN";
|
var errorStatus = "UNKNOWN";
|
||||||
|
|
||||||
if (IsKnownWinProgramError(e, callingMethodName) || IsKnownUWPProgramError(e, callingMethodName))
|
if (IsKnownWinProgramError(ex, methodName) || IsKnownUWPProgramError(ex, methodName))
|
||||||
{
|
{
|
||||||
possibleResolution = "Can be ignored and Wox should still continue, however the program may not be loaded";
|
possibleResolution = "Can be ignored and Wox should still continue, however the program may not be loaded";
|
||||||
errorStatus = "KNOWN";
|
errorStatus = "KNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
var calledMethod = e.TargetSite != null ? e.TargetSite.ToString() : e.StackTrace;
|
var calledMethod = ex.TargetSite != null ? ex.TargetSite.ToString() : ex.StackTrace;
|
||||||
|
|
||||||
calledMethod = string.IsNullOrEmpty(calledMethod) ? "Not available" : calledMethod;
|
calledMethod = string.IsNullOrEmpty(calledMethod) ? "Not available" : calledMethod;
|
||||||
var msg = $"Error status: {errorStatus}"
|
var msg = $"\tError status: {errorStatus}"
|
||||||
+ $"\nProgram path: {loadingProgramPath}"
|
+ $"\n\t\tProgram path: {loadingProgramPath}"
|
||||||
+ $"\nException thrown in called method: {calledMethod}"
|
+ $"\n\t\tException thrown in called method: {calledMethod}"
|
||||||
+ $"\nPossible interpretation of the error: {interpretationMessage}"
|
+ $"\n\t\tPossible interpretation of the error: {message}"
|
||||||
+ $"\nPossible resolution: {possibleResolution}";
|
+ $"\n\t\tPossible resolution: {possibleResolution}";
|
||||||
|
|
||||||
// removed looping logic since that is inside Log class
|
// removed looping logic since that is inside Log class
|
||||||
Log.Exception(classname, msg, e, callingMethodName);
|
Log.Exception(msg, ex, fullClassName, methodName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Please follow exception format: |class name|calling method name|loading program path|user friendly message that explains the error
|
|
||||||
/// => Example: |Win32|LnkProgram|c:\..\chrome.exe|Permission denied on directory, but Wox should continue
|
|
||||||
/// </summary>
|
|
||||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
||||||
internal static void LogException(string message, Exception e)
|
|
||||||
{
|
|
||||||
var parts = message.Split('|');
|
|
||||||
if (parts.Length < 4)
|
|
||||||
{
|
|
||||||
Log.Exception($"|ProgramLogger|LogException|Fail to log exception in program logger, parts length is too small: {parts.Length}, message: {message}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
var classname = parts[1];
|
|
||||||
var callingMethodName = parts[2];
|
|
||||||
var loadingProgramPath = parts[3];
|
|
||||||
var interpretationMessage = parts[4];
|
|
||||||
|
|
||||||
LogException(classname, callingMethodName, loadingProgramPath, interpretationMessage, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsKnownWinProgramError(Exception e, string callingMethodName)
|
private static bool IsKnownWinProgramError(Exception e, string callingMethodName)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using Microsoft.Plugin.Program.Logger;
|
using Microsoft.Plugin.Program.Logger;
|
||||||
using Package = Windows.ApplicationModel.Package;
|
using Package = Windows.ApplicationModel.Package;
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e) when (e is ArgumentException || e is FileNotFoundException || e is DirectoryNotFoundException)
|
catch (Exception e) when (e is ArgumentException || e is FileNotFoundException || e is DirectoryNotFoundException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException($"PackageWrapper", "GetWrapperFromPackage", "Path could not be determined", $"Exception {package.Id.Name}", e);
|
ProgramLogger.Exception($"Exception {package.Id.Name}", e, MethodBase.GetCurrentMethod().DeclaringType, "Path could not be determined");
|
||||||
return new PackageWrapper(
|
return new PackageWrapper(
|
||||||
package.Id.Name,
|
package.Id.Name,
|
||||||
package.Id.FullName,
|
package.Id.FullName,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(nameof(PackageManagerWrapper), e.Message, nameof(FindPackagesForCurrentUser));
|
Log.Error(e.Message, GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (System.IO.FileNotFoundException ex)
|
catch (System.IO.FileNotFoundException ex)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException($"|Win32| ShellLinkHelper.retrieveTargetPath | {path} | Path could not be retrieved", ex);
|
ProgramLogger.Exception("Path could not be retrieved", ex, GetType(), path);
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@@ -80,9 +81,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var e = Marshal.GetExceptionForHR((int)hResult);
|
var e = Marshal.GetExceptionForHR((int)hResult);
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception("Error caused while trying to get the details of the UWP program", e, GetType(), path);
|
||||||
$"|UWP|InitializeAppInfo|{path}" +
|
|
||||||
"|Error caused while trying to get the details of the UWP program", e);
|
|
||||||
|
|
||||||
Apps = new List<UWPApplication>().ToArray();
|
Apps = new List<UWPApplication>().ToArray();
|
||||||
}
|
}
|
||||||
@@ -104,7 +103,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Error($"|UWP.XmlNamespaces|Error occurred while trying to get the XML from {path}");
|
Log.Error($"Error occurred while trying to get the XML from {path}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
return Array.Empty<string>();
|
return Array.Empty<string>();
|
||||||
}
|
}
|
||||||
@@ -128,10 +127,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Trying to get the package version of the UWP program, but a unknown UWP appmanifest version {FullName} from location {Location} is returned.", new FormatException(), GetType(), Location);
|
||||||
$"|UWP|XmlNamespaces|{Location}" +
|
|
||||||
"|Trying to get the package version of the UWP program, but a unknown UWP appmanifest version "
|
|
||||||
+ $"{FullName} from location {Location} is returned.", new FormatException());
|
|
||||||
|
|
||||||
Version = PackageVersion.Unknown;
|
Version = PackageVersion.Unknown;
|
||||||
}
|
}
|
||||||
@@ -153,9 +149,8 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"Unable to convert Package to UWP for {p.FullName}", e, MethodBase.GetCurrentMethod().DeclaringType, p.InstalledLocation);
|
||||||
$"|UWP|All|{p.InstalledLocation}|An unexpected error occurred and "
|
|
||||||
+ $"unable to convert Package to UWP for {p.FullName}", e);
|
|
||||||
return Array.Empty<UWPApplication>();
|
return Array.Empty<UWPApplication>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +185,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException("UWP", "CurrentUserPackages", $"id", "An unexpected error occurred and unable to verify if package is valid", e);
|
ProgramLogger.Exception("An unexpected error occurred and unable to verify if package is valid", e, MethodBase.GetCurrentMethod().DeclaringType, "id");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Program.UWP.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
|
Log.Exception($"Failed to open {Name} in console, {e.Message}", e, GetType());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -310,9 +310,8 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"Can't load null or empty result pri {source} in uwp location {Package.Location}", new NullReferenceException(), GetType(), Package.Location);
|
||||||
$"|UWP|ResourceFromPri|{Package.Location}|Can't load null or empty result "
|
|
||||||
+ $"pri {source} in uwp location {Package.Location}", new NullReferenceException());
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,7 +324,8 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
// 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
|
||||||
var e = Marshal.GetExceptionForHR((int)hResult);
|
var e = Marshal.GetExceptionForHR((int)hResult);
|
||||||
ProgramLogger.LogException($"|UWP|ResourceFromPri|{Package.Location}|Load pri failed {source} with HResult {hResult} and location {Package.Location}", e);
|
ProgramLogger.Exception($"Load pri failed {source} with HResult {hResult} and location {Package.Location}", e, GetType(), Package.Location);
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -569,9 +569,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
{
|
{
|
||||||
LogoPath = string.Empty;
|
LogoPath = string.Empty;
|
||||||
LogoType = LogoType.Error;
|
LogoType = LogoType.Error;
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException(), GetType(), Package.Location);
|
||||||
$"|UWP|LogoPathFromUri|{Package.Location}" +
|
|
||||||
$"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -589,6 +587,8 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const int _dpiScale100 = 96;
|
||||||
|
|
||||||
private ImageSource PlatedImage(BitmapImage image)
|
private ImageSource PlatedImage(BitmapImage image)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(BackgroundColor))
|
if (!string.IsNullOrEmpty(BackgroundColor))
|
||||||
@@ -630,21 +630,21 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
var context = visual.RenderOpen();
|
var context = visual.RenderOpen();
|
||||||
context.DrawDrawing(group);
|
context.DrawDrawing(group);
|
||||||
context.Close();
|
context.Close();
|
||||||
const int dpiScale100 = 96;
|
|
||||||
var bitmap = new RenderTargetBitmap(
|
var bitmap = new RenderTargetBitmap(
|
||||||
Convert.ToInt32(width),
|
Convert.ToInt32(width),
|
||||||
Convert.ToInt32(height),
|
Convert.ToInt32(height),
|
||||||
dpiScale100,
|
_dpiScale100,
|
||||||
dpiScale100,
|
_dpiScale100,
|
||||||
PixelFormats.Pbgra32);
|
PixelFormats.Pbgra32);
|
||||||
|
|
||||||
bitmap.Render(visual);
|
bitmap.Render(visual);
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"Unable to convert background string {BackgroundColor} to color for {Package.Location}", new InvalidOperationException(), GetType(), Package.Location);
|
||||||
$"|UWP|PlatedImage|{Package.Location}|Unable to convert background string {BackgroundColor} " +
|
|
||||||
$"to color for {Package.Location}", new InvalidOperationException());
|
|
||||||
|
|
||||||
return new BitmapImage(new Uri(Constant.ErrorIcon));
|
return new BitmapImage(new Uri(Constant.ErrorIcon));
|
||||||
}
|
}
|
||||||
@@ -674,9 +674,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"Unable to get logo for {UserModelId} from {path} and located in {Package.Location}", new FileNotFoundException(), GetType(), path);
|
||||||
$"|UWP|ImageFromPath|{path}|Unable to get logo for {UserModelId} from {path} and" +
|
|
||||||
$" located in {Package.Location}", new FileNotFoundException());
|
|
||||||
return new BitmapImage(new Uri(ImageLoader.ErrorIconPath));
|
return new BitmapImage(new Uri(ImageLoader.ErrorIconPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Program.Win32.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
|
Log.Exception($"|Failed to open {Name} in console, {e.Message}", e, GetType());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -351,9 +351,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||||
$"|Win32|Win32Program|{path}" +
|
|
||||||
$"|Permission denied when trying to load the program from {path}", e);
|
|
||||||
|
|
||||||
return new Win32Program() { Valid = false, Enabled = false };
|
return new Win32Program() { Valid = false, Enabled = false };
|
||||||
}
|
}
|
||||||
@@ -386,7 +384,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
{
|
{
|
||||||
// To catch the exception if the uri cannot be parsed.
|
// To catch the exception if the uri cannot be parsed.
|
||||||
// Link to watson crash: https://watsonportal.microsoft.com/Failure?FailureSearchText=5f871ea7-e886-911f-1b31-131f63f6655b
|
// Link to watson crash: https://watsonportal.microsoft.com/Failure?FailureSearchText=5f871ea7-e886-911f-1b31-131f63f6655b
|
||||||
ProgramLogger.LogException($"|Win32Program|InternetShortcutProgram|{urlPath}|url could not be parsed", e);
|
ProgramLogger.Exception($"url could not be parsed", e, MethodBase.GetCurrentMethod().DeclaringType, urlPath);
|
||||||
return new Win32Program() { Valid = false, Enabled = false };
|
return new Win32Program() { Valid = false, Enabled = false };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,9 +424,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||||
$"|Win32|InternetShortcutProgram|{path}" +
|
|
||||||
$"|Permission denied when trying to load the program from {path}", e);
|
|
||||||
|
|
||||||
return new Win32Program() { Valid = false, Enabled = false };
|
return new Win32Program() { Valid = false, Enabled = false };
|
||||||
}
|
}
|
||||||
@@ -476,9 +472,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
// Error caused likely due to trying to get the description of the program
|
// Error caused likely due to trying to get the description of the program
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception("An unexpected error occurred in the calling method LnkProgram", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||||
$"|Win32|LnkProgram|{path}" +
|
|
||||||
"|An unexpected error occurred in the calling method LnkProgram", e);
|
|
||||||
|
|
||||||
program.Valid = false;
|
program.Valid = false;
|
||||||
return program;
|
return program;
|
||||||
@@ -501,17 +495,13 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||||
$"|Win32|ExeProgram|{path}" +
|
|
||||||
$"|Permission denied when trying to load the program from {path}", e);
|
|
||||||
|
|
||||||
return new Win32Program() { Valid = false, Enabled = false };
|
return new Win32Program() { Valid = false, Enabled = false };
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Unable to locate exe file at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||||
$"|Win32|ExeProgram|{path}" +
|
|
||||||
$"|Unable to locate exe file at {path}", e);
|
|
||||||
|
|
||||||
return new Win32Program() { Valid = false, Enabled = false };
|
return new Win32Program() { Valid = false, Enabled = false };
|
||||||
}
|
}
|
||||||
@@ -619,17 +609,13 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (DirectoryNotFoundException e)
|
catch (DirectoryNotFoundException e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception("|The directory trying to load the program from does not exist", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
|
||||||
"|The directory trying to load the program from does not exist", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
|
||||||
$"|Permission denied when trying to load programs from {currentDirectory}", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -647,9 +633,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
|
||||||
$"|Permission denied when trying to load programs from {currentDirectory}", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (folderQueue.Any());
|
while (folderQueue.Any());
|
||||||
@@ -841,9 +825,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException(
|
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||||
$"|Win32|GetProgramPathFromRegistrySubKeys|{path}" +
|
|
||||||
$"|Permission denied when trying to load the program from {path}", e);
|
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
@@ -963,7 +945,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException("|Win32|All|Not available|An unexpected error occurred", e);
|
ProgramLogger.Exception("An unexpected error occurred", e, MethodBase.GetCurrentMethod().DeclaringType, "Not available");
|
||||||
|
|
||||||
return Array.Empty<Win32Program>();
|
return Array.Empty<Win32Program>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Microsoft.Plugin.Program.Storage
|
|||||||
// eg. "Could not find file 'C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminalPreview_2020.616.45.0_neutral_~_8wekyb3d8bbwe\\AppxManifest.xml'."
|
// eg. "Could not find file 'C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminalPreview_2020.616.45.0_neutral_~_8wekyb3d8bbwe\\AppxManifest.xml'."
|
||||||
catch (System.IO.FileNotFoundException e)
|
catch (System.IO.FileNotFoundException e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException($"|UWP|OnPackageInstalling|{args.Package.InstalledLocation}|{e.Message}", e);
|
ProgramLogger.Exception(e.Message, e, GetType(), args.Package.InstalledLocation.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +66,7 @@ namespace Microsoft.Plugin.Program.Storage
|
|||||||
var packageWrapper = PackageWrapper.GetWrapperFromPackage(args.Package);
|
var packageWrapper = PackageWrapper.GetWrapperFromPackage(args.Package);
|
||||||
var uwp = new UWP(packageWrapper);
|
var uwp = new UWP(packageWrapper);
|
||||||
var apps = Items.Where(a => a.Package.Equals(uwp)).ToArray();
|
var apps = Items.Where(a => a.Package.Equals(uwp)).ToArray();
|
||||||
|
|
||||||
foreach (var app in apps)
|
foreach (var app in apps)
|
||||||
{
|
{
|
||||||
Remove(app);
|
Remove(app);
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace Microsoft.Plugin.Program.Storage
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Info($"|Win32ProgramRepository|OnAppRenamed-{extension}Program|{oldPath}|Unable to create program from {oldPath}| {ex.Message}");
|
Log.Exception($"OnAppRenamed-{extension}Program|{oldPath}|Unable to create program from {oldPath}", ex, GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// To remove the old app which has been renamed and to add the new application.
|
// To remove the old app which has been renamed and to add the new application.
|
||||||
@@ -134,7 +134,7 @@ namespace Microsoft.Plugin.Program.Storage
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Info($"|Win32ProgramRepository|OnAppDeleted-{extension}Program|{path}|Unable to create program from {path}| {ex.Message}");
|
Log.Exception($"OnAppDeleted-{extension}Program|{path}|Unable to create program from {path}", ex, GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app != null)
|
if (app != null)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Shell.Main.Query|Exception when query for <{query}>", e);
|
Log.Exception($"Exception when query for <{query}>", e, GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace Microsoft.Plugin.Uri
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
BrowserIconPath = DefaultIconPath;
|
BrowserIconPath = DefaultIconPath;
|
||||||
Log.Exception("Exception when retreiving icon", e);
|
Log.Exception("Exception when retreiving icon", e, GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,8 +82,9 @@ namespace PowerLauncher
|
|||||||
bootTime.Start();
|
bootTime.Start();
|
||||||
Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
|
Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
|
||||||
{
|
{
|
||||||
Log.Info("|App.OnStartup|Begin PowerToys Run startup ----------------------------------------------------");
|
Log.Info("Begin PowerToys Run startup ----------------------------------------------------", GetType());
|
||||||
Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
|
Log.Info($"Runtime info:{ErrorReporting.RuntimeInfo()}", GetType());
|
||||||
|
|
||||||
RegisterAppDomainExceptions();
|
RegisterAppDomainExceptions();
|
||||||
RegisterDispatcherUnhandledException();
|
RegisterDispatcherUnhandledException();
|
||||||
|
|
||||||
@@ -118,7 +119,7 @@ namespace PowerLauncher
|
|||||||
_mainVM.MainWindowVisibility = Visibility.Visible;
|
_mainVM.MainWindowVisibility = Visibility.Visible;
|
||||||
_mainVM.ColdStartFix();
|
_mainVM.ColdStartFix();
|
||||||
_themeManager.ThemeChanged += OnThemeChanged;
|
_themeManager.ThemeChanged += OnThemeChanged;
|
||||||
Log.Info("|App.OnStartup|End PowerToys Run startup ---------------------------------------------------- ");
|
Log.Info("End PowerToys Run startup ---------------------------------------------------- ", GetType());
|
||||||
|
|
||||||
bootTime.Stop();
|
bootTime.Stop();
|
||||||
|
|
||||||
@@ -178,7 +179,7 @@ namespace PowerLauncher
|
|||||||
{
|
{
|
||||||
Stopwatch.Normal("|App.OnExit|Exit cost", () =>
|
Stopwatch.Normal("|App.OnExit|Exit cost", () =>
|
||||||
{
|
{
|
||||||
Log.Info("|App.OnExit| Start PowerToys Run Exit---------------------------------------------------- ");
|
Log.Info("Start PowerToys Run Exit---------------------------------------------------- ", GetType());
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (_themeManager != null)
|
if (_themeManager != null)
|
||||||
@@ -198,7 +199,7 @@ namespace PowerLauncher
|
|||||||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||||
// TODO: set large fields to null
|
// TODO: set large fields to null
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
Log.Info("|App.OnExit| End PowerToys Run Exit ---------------------------------------------------- ");
|
Log.Info("End PowerToys Run Exit ---------------------------------------------------- ", GetType());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ namespace PowerLauncher
|
|||||||
// Hence, there can be a situation where the element index that we want to scroll into view is out of range for it's parent control.
|
// Hence, there can be a situation where the element index that we want to scroll into view is out of range for it's parent control.
|
||||||
// To mitigate this we use the UpdateLayout function, which forces layout update to ensure that the parent element contains the latest properties.
|
// To mitigate this we use the UpdateLayout function, which forces layout update to ensure that the parent element contains the latest properties.
|
||||||
// However, it has a performance impact and is therefore not called each time.
|
// However, it has a performance impact and is therefore not called each time.
|
||||||
Log.Exception("MainWindow", "The parent element layout is not updated yet", ex, "SuggestionsList_SelectionChanged");
|
Log.Exception("The parent element layout is not updated yet", ex, GetType());
|
||||||
listview.UpdateLayout();
|
listview.UpdateLayout();
|
||||||
listview.ScrollIntoView(e.AddedItems[0]);
|
listview.ScrollIntoView(e.AddedItems[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace PowerLauncher
|
|||||||
{
|
{
|
||||||
if (!_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
|
if (!_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
|
||||||
{
|
{
|
||||||
Log.Info("|SettingsWatcher.OverloadSettings|PT Run settings.json was missing, creating a new one");
|
Log.Info("PT Run settings.json was missing, creating a new one", GetType());
|
||||||
|
|
||||||
var defaultSettings = new PowerLauncherSettings();
|
var defaultSettings = new PowerLauncherSettings();
|
||||||
defaultSettings.Save(_settingsUtils);
|
defaultSettings.Save(_settingsUtils);
|
||||||
@@ -110,7 +110,7 @@ namespace PowerLauncher
|
|||||||
if (retryCount > MaxRetries)
|
if (retryCount > MaxRetries)
|
||||||
{
|
{
|
||||||
retry = false;
|
retry = false;
|
||||||
Log.Exception($"|SettingsWatcher.OverloadSettings| Failed to Deserialize PowerToys settings, Retrying {e.Message}", e);
|
Log.Exception($"Failed to Deserialize PowerToys settings, Retrying {e.Message}", e, GetType());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ namespace PowerLauncher
|
|||||||
if (retryCount > MaxRetries)
|
if (retryCount > MaxRetries)
|
||||||
{
|
{
|
||||||
retry = false;
|
retry = false;
|
||||||
Log.Exception($"|SettingsWatcher.OverloadSettings| Failed to Deserialize PowerToys settings, Creating new settings as file could be corrupted {e.Message}", e);
|
Log.Exception($"Failed to Deserialize PowerToys settings, Creating new settings as file could be corrupted {e.Message}", e, GetType());
|
||||||
|
|
||||||
// Settings.json could possibly be corrupted. To mitigate this we delete the
|
// Settings.json could possibly be corrupted. To mitigate this we delete the
|
||||||
// current file and replace it with a correct json value.
|
// current file and replace it with a correct json value.
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
#pragma warning restore CA1031 // Do not catch general exception types
|
#pragma warning restore CA1031 // Do not catch general exception types
|
||||||
{
|
{
|
||||||
Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e);
|
Log.Exception($"IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e, GetType());
|
||||||
imagePath = ImageLoader.ErrorIconPath;
|
imagePath = ImageLoader.ErrorIconPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|JsonRPCPlugin.Query|Exception when query <{query}>", e);
|
Log.Exception($"Exception when query <{query}>", e, GetType());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|JsonRPCPlugin.LoadContextMenus| THIS IS A BUG - Exception on result <{selectedResult}>", e);
|
Log.Exception($"THIS IS A BUG - Exception on result <{selectedResult}>", e, GetType());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,12 +179,14 @@ namespace Wox.Core.Plugin
|
|||||||
var error = standardError.ReadToEnd();
|
var error = standardError.ReadToEnd();
|
||||||
if (!string.IsNullOrEmpty(error))
|
if (!string.IsNullOrEmpty(error))
|
||||||
{
|
{
|
||||||
Log.Error($"|JsonRPCPlugin.Execute|{error}");
|
Log.Error(error, GetType());
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Error("|JsonRPCPlugin.Execute|Empty standard output and standard error.");
|
Log.Error("Empty standard output and standard error.", GetType());
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,6 +194,7 @@ namespace Wox.Core.Plugin
|
|||||||
else if (result.StartsWith("DEBUG:"))
|
else if (result.StartsWith("DEBUG:"))
|
||||||
{
|
{
|
||||||
MessageBox.Show(new Form { TopMost = true }, result.Substring(6));
|
MessageBox.Show(new Form { TopMost = true }, result.Substring(6));
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -202,14 +205,16 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Error("|JsonRPCPlugin.Execute|Can't start new process");
|
Log.Error("Can't start new process", GetType());
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|JsonRPCPlugin.Execute|Exception for filename <{startInfo.FileName}> with argument <{startInfo.Arguments}>", e);
|
Log.Exception($"Exception for filename <{startInfo.FileName}> with argument <{startInfo.Arguments}>", e, GetType());
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
@@ -27,6 +28,7 @@ namespace Wox.Core.Plugin
|
|||||||
PluginMetadatas.Clear();
|
PluginMetadatas.Clear();
|
||||||
var directories = pluginDirectories.SelectMany(Directory.GetDirectories);
|
var directories = pluginDirectories.SelectMany(Directory.GetDirectories);
|
||||||
ParsePluginConfigs(directories);
|
ParsePluginConfigs(directories);
|
||||||
|
|
||||||
return PluginMetadatas;
|
return PluginMetadatas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|PluginConfig.ParsePLuginConfigs|Can't delete <{directory}>", e);
|
Log.Exception($"Can't delete <{directory}>", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -62,7 +64,8 @@ namespace Wox.Core.Plugin
|
|||||||
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
|
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
|
||||||
if (!File.Exists(configPath))
|
if (!File.Exists(configPath))
|
||||||
{
|
{
|
||||||
Log.Error($"|PluginConfig.GetPluginMetadata|Didn't find config file <{configPath}>");
|
Log.Error($"Didn't find config file <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,19 +83,19 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|PluginConfig.GetPluginMetadata|invalid json for config <{configPath}>", e);
|
Log.Exception($"|PluginConfig.GetPluginMetadata|invalid json for config <{configPath}>", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||||
{
|
{
|
||||||
Log.Error($"|PluginConfig.GetPluginMetadata|Invalid language <{metadata.Language}> for config <{configPath}>");
|
Log.Error($"|PluginConfig.GetPluginMetadata|Invalid language <{metadata.Language}> for config <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!File.Exists(metadata.ExecuteFilePath))
|
if (!File.Exists(metadata.ExecuteFilePath))
|
||||||
{
|
{
|
||||||
Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}");
|
Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
@@ -103,11 +104,11 @@ namespace Wox.Core.Plugin
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
pair.Metadata.InitTime += milliseconds;
|
pair.Metadata.InitTime += milliseconds;
|
||||||
Log.Info($"|PluginManager.InitializePlugins|Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>");
|
Log.Info($"Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception(nameof(PluginManager), $"Fail to Init plugin: {pair.Metadata.Name}", e);
|
Log.Exception($"Fail to Init plugin: {pair.Metadata.Name}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
pair.Metadata.Disabled = true;
|
pair.Metadata.Disabled = true;
|
||||||
failedPlugins.Enqueue(pair);
|
failedPlugins.Enqueue(pair);
|
||||||
}
|
}
|
||||||
@@ -175,13 +176,16 @@ namespace Wox.Core.Plugin
|
|||||||
UpdateResultWithActionKeyword(results, query);
|
UpdateResultWithActionKeyword(results, query);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
metadata.QueryCount += 1;
|
metadata.QueryCount += 1;
|
||||||
metadata.AvgQueryTime = metadata.QueryCount == 1 ? milliseconds : (metadata.AvgQueryTime + milliseconds) / 2;
|
metadata.AvgQueryTime = metadata.QueryCount == 1 ? milliseconds : (metadata.AvgQueryTime + milliseconds) / 2;
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
|
Log.Exception($"Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
return new List<Result>();
|
return new List<Result>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,11 +249,13 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var results = plugin.LoadContextMenus(result);
|
var results = plugin.LoadContextMenus(result);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|PluginManager.GetContextMenusForPlugin|Can't load context menus for plugin <{metadata.Name}>", e);
|
Log.Exception($"Can't load context menus for plugin <{metadata.Name}>", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
return new List<ContextMenuResult>();
|
return new List<ContextMenuResult>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Infrastructure.Logger.Log.Exception($"|PluginsLoader.CSharpPlugins|Couldn't load assembly for {metadata.Name}", e);
|
Infrastructure.Logger.Log.Exception($"Couldn't load assembly for {metadata.Name}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (InvalidOperationException e)
|
catch (InvalidOperationException e)
|
||||||
{
|
{
|
||||||
Infrastructure.Logger.Log.Exception($"|PluginsLoader.CSharpPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e);
|
Infrastructure.Logger.Log.Exception($"Can't find class implement IPlugin for <{metadata.Name}>", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Infrastructure.Logger.Log.Exception($"|PluginsLoader.CSharpPlugins|Can't create instance for <{metadata.Name}>", e);
|
Infrastructure.Logger.Log.Exception($"Can't create instance for <{metadata.Name}>", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -96,6 +96,7 @@ namespace Wox.Core.Plugin
|
|||||||
Plugin = new ExecutablePlugin(metadata.ExecuteFilePath),
|
Plugin = new ExecutablePlugin(metadata.ExecuteFilePath),
|
||||||
Metadata = metadata,
|
Metadata = metadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Wox.Infrastructure
|
|||||||
// force pinyin library static constructor initialize
|
// force pinyin library static constructor initialize
|
||||||
PinyinHelper.toHanyuPinyinStringArray('T', _pinyinFormat);
|
PinyinHelper.toHanyuPinyinStringArray('T', _pinyinFormat);
|
||||||
});
|
});
|
||||||
Log.Info($"|Wox.Infrastructure.Alphabet.Initialize|Number of preload pinyin combination<{_pinyinCache.Count}>");
|
Log.Info($"Number of preload pinyin combination<{_pinyinCache.Count}>", GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Translate(string str)
|
public string Translate(string str)
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ namespace Wox.Infrastructure.FileSystemHelper
|
|||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
Log.Info($"File {path} is being accessed by another process| {ex.Message}");
|
Log.Info($"File {path} is being accessed by another process| {ex.Message}", GetType());
|
||||||
|
|
||||||
return new string[] { string.Empty };
|
return new string[] { string.Empty };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
@@ -95,7 +96,7 @@ namespace Wox.Infrastructure
|
|||||||
}
|
}
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
Log.Exception($"Wox.Infrastructure.Helper| Unable to Run {path} as admin : {ex.Message}", ex);
|
Log.Exception($"Unable to Run {path} as admin : {ex.Message}", ex, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -61,7 +62,8 @@ namespace Wox.Infrastructure.Http
|
|||||||
|
|
||||||
public static async Task<string> Get([NotNull] string url, string encoding = "UTF-8")
|
public static async Task<string> Get([NotNull] string url, string encoding = "UTF-8")
|
||||||
{
|
{
|
||||||
Log.Debug($"|Http.Get|Url <{url}>");
|
Log.Debug($"Url <{url}>", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
var request = WebRequest.CreateHttp(url);
|
var request = WebRequest.CreateHttp(url);
|
||||||
request.Method = "GET";
|
request.Method = "GET";
|
||||||
request.Timeout = 1000;
|
request.Timeout = 1000;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
@@ -62,7 +63,8 @@ namespace Wox.Infrastructure.Image
|
|||||||
Load(x.Key);
|
Load(x.Key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Log.Info($"|ImageLoader.Initialize|Number of preload images is <{ImageCache.Usage.Count}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
|
|
||||||
|
Log.Info($"Number of preload images is <{ImageCache.Usage.Count}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +190,7 @@ namespace Wox.Infrastructure.Image
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|ImageLoader.Load|Failed to get thumbnail for {path}", e);
|
Log.Exception($"Failed to get thumbnail for {path}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
type = ImageType.Error;
|
type = ImageType.Error;
|
||||||
image = ImageCache[ErrorIconPath];
|
image = ImageCache[ErrorIconPath];
|
||||||
ImageCache[path] = image;
|
ImageCache[path] = image;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using NLog;
|
using NLog;
|
||||||
@@ -37,67 +38,25 @@ namespace Wox.Infrastructure.Logger
|
|||||||
LogManager.Configuration = configuration;
|
LogManager.Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LogFaultyFormat(string message)
|
private static void LogInternalException(string message, System.Exception e, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
var logger = LogManager.GetLogger("FaultyLogger");
|
var logger = GetLogger(fullClassName.FullName, methodName);
|
||||||
message = $"Wrong logger message format <{message}>";
|
|
||||||
System.Diagnostics.Debug.WriteLine($"FATAL|{message}");
|
|
||||||
logger.Fatal(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool FormatValid(string message)
|
LogInternal(LogLevel.Error, message, fullClassName, logger, methodName, sourceFilePath, sourceLineNumber);
|
||||||
{
|
|
||||||
var parts = message.Split('|');
|
|
||||||
var valid = parts.Length == 3 && !string.IsNullOrWhiteSpace(parts[1]) && !string.IsNullOrWhiteSpace(parts[2]);
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
||||||
public static void Exception(string className, string message, System.Exception exception, [CallerMemberName] string methodName = "")
|
|
||||||
{
|
|
||||||
var classNameWithMethod = CheckClassAndMessageAndReturnFullClassWithMethod(className, message, methodName);
|
|
||||||
|
|
||||||
ExceptionInternal(classNameWithMethod, message, exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CheckClassAndMessageAndReturnFullClassWithMethod(string className, string message, string methodName)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(className))
|
|
||||||
{
|
|
||||||
LogFaultyFormat($"Fail to specify a class name during logging of message: {message ?? "no message entered"}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(message))
|
|
||||||
{
|
|
||||||
// todo: not sure we really need that
|
|
||||||
LogFaultyFormat($"Fail to specify a message during logging");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(methodName))
|
|
||||||
{
|
|
||||||
return className + "." + methodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ExceptionInternal(string classAndMethod, string message, System.Exception e)
|
|
||||||
{
|
|
||||||
var logger = LogManager.GetLogger(classAndMethod);
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine($"ERROR|{message}");
|
|
||||||
|
|
||||||
logger.Error("-------------------------- Begin exception --------------------------");
|
logger.Error("-------------------------- Begin exception --------------------------");
|
||||||
logger.Error(message);
|
logger.Error($"\n\tMessage:\n\t {message}");
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
logger.Error($"Exception full name:\n <{e.GetType().FullName}>");
|
logger.Error(
|
||||||
logger.Error($"Exception message:\n <{e.Message}>");
|
$"\n\tException full name:\n\t <{e.GetType().FullName}>" +
|
||||||
logger.Error($"Exception stack trace:\n <{e.StackTrace}>");
|
$"\n\tException message:\n\t <{e.Message}>" +
|
||||||
logger.Error($"Exception source:\n <{e.Source}>");
|
$"\n\tException stack trace:\n\t <{e.StackTrace}>" +
|
||||||
logger.Error($"Exception target site:\n <{e.TargetSite}>");
|
$"\n\tException source:\n\t <{e.Source}>" +
|
||||||
logger.Error($"Exception HResult:\n <{e.HResult}>");
|
$"\n\tException target site:\n\t <{e.TargetSite}>" +
|
||||||
|
$"\n\tException HResult:\n\t <{e.HResult}>");
|
||||||
|
|
||||||
e = e.InnerException;
|
e = e.InnerException;
|
||||||
}
|
}
|
||||||
while (e != null);
|
while (e != null);
|
||||||
@@ -105,93 +64,53 @@ namespace Wox.Infrastructure.Logger
|
|||||||
logger.Error("-------------------------- End exception --------------------------");
|
logger.Error("-------------------------- End exception --------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LogInternal(string message, LogLevel level)
|
public static void Info(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
if (FormatValid(message))
|
LogInternal(LogLevel.Info, message, fullClassName, methodName, sourceFilePath, sourceLineNumber);
|
||||||
{
|
|
||||||
var parts = message.Split('|');
|
|
||||||
var prefix = parts[1];
|
|
||||||
var unprefixed = parts[2];
|
|
||||||
var logger = LogManager.GetLogger(prefix);
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine($"{level.Name}|{message}");
|
|
||||||
logger.Log(level, unprefixed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogFaultyFormat(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="message">example: "|prefix|unprefixed" </param>
|
public static void Debug(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
||||||
public static void Exception(string message, System.Exception e)
|
|
||||||
{
|
{
|
||||||
if (FormatValid(message))
|
LogInternal(LogLevel.Debug, message, fullClassName, methodName, sourceFilePath, sourceLineNumber);
|
||||||
{
|
|
||||||
var parts = message.Split('|');
|
|
||||||
var prefix = parts[1];
|
|
||||||
var unprefixed = parts[2];
|
|
||||||
ExceptionInternal(prefix, unprefixed, e);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogFaultyFormat(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="message">example: "|prefix|unprefixed" </param>
|
public static void Warn(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
public static void Error(string message)
|
|
||||||
{
|
{
|
||||||
LogInternal(message, LogLevel.Error);
|
LogInternal(LogLevel.Warn, message, fullClassName, methodName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Error(string className, string message, [CallerMemberName] string methodName = "")
|
public static void Error(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
LogInternal(LogLevel.Error, className, message, methodName);
|
LogInternal(LogLevel.Error, message, fullClassName, methodName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LogInternal(LogLevel level, string className, string message, [CallerMemberName] string methodName = "")
|
public static void Exception(string message, System.Exception ex, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
var classNameWithMethod = CheckClassAndMessageAndReturnFullClassWithMethod(className, message, methodName);
|
LogInternalException(message, ex, fullClassName, methodName, sourceFilePath, sourceLineNumber);
|
||||||
|
|
||||||
var logger = LogManager.GetLogger(classNameWithMethod);
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine($"{level.Name}|{message}");
|
|
||||||
logger.Log(level, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Debug(string className, string message, [CallerMemberName] string methodName = "")
|
private static void LogInternal(LogLevel level, string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
LogInternal(LogLevel.Debug, className, message, methodName);
|
var logger = GetLogger(fullClassName.FullName, methodName);
|
||||||
|
|
||||||
|
LogInternal(level, message, fullClassName, logger, methodName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="message">example: "|prefix|unprefixed" </param>
|
private static void LogInternal(LogLevel level, string message, Type fullClassName, NLog.Logger logger, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
public static void Debug(string message)
|
|
||||||
{
|
{
|
||||||
LogInternal(message, LogLevel.Debug);
|
// System.Diagnostics.Debug.WriteLine($" {level.Name} | {message}");
|
||||||
|
var msg = $"\n\tMessage: {message}" +
|
||||||
|
$"\n\tArea: {fullClassName}.{methodName}" +
|
||||||
|
$"\n\tSource Path: {sourceFilePath}::{sourceLineNumber}\n";
|
||||||
|
|
||||||
|
logger.Log(level, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Info(string className, string message, [CallerMemberName] string methodName = "")
|
private static NLog.Logger GetLogger(string fullClassName, string methodName)
|
||||||
{
|
{
|
||||||
LogInternal(LogLevel.Info, className, message, methodName);
|
var classNameWithMethod = $"{fullClassName}.{methodName}";
|
||||||
}
|
|
||||||
|
|
||||||
/// <param name="message">example: "|prefix|unprefixed" </param>
|
return LogManager.GetLogger(classNameWithMethod);
|
||||||
public static void Info(string message)
|
|
||||||
{
|
|
||||||
LogInternal(message, LogLevel.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Warn(string className, string message, [CallerMemberName] string methodName = "")
|
|
||||||
{
|
|
||||||
LogInternal(LogLevel.Warn, className, message, methodName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <param name="message">example: "|prefix|unprefixed" </param>
|
|
||||||
public static void Warn(string message)
|
|
||||||
{
|
|
||||||
LogInternal(message, LogLevel.Warn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
|
|
||||||
namespace Wox.Infrastructure
|
namespace Wox.Infrastructure
|
||||||
@@ -24,7 +25,7 @@ namespace Wox.Infrastructure
|
|||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
var milliseconds = stopWatch.ElapsedMilliseconds;
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||||
string info = $"{message} <{milliseconds}ms>";
|
string info = $"{message} <{milliseconds}ms>";
|
||||||
Log.Debug(info);
|
Log.Debug(info, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return milliseconds;
|
return milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ namespace Wox.Infrastructure
|
|||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
var milliseconds = stopWatch.ElapsedMilliseconds;
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||||
string info = $"{message} <{milliseconds}ms>";
|
string info = $"{message} <{milliseconds}ms>";
|
||||||
Log.Info(info);
|
Log.Info(info, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
return milliseconds;
|
return milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ namespace Wox.Infrastructure
|
|||||||
foreach (var key in Count.Keys)
|
foreach (var key in Count.Keys)
|
||||||
{
|
{
|
||||||
string info = $"{key} already cost {Count[key]}ms";
|
string info = $"{key} already cost {Count[key]}ms";
|
||||||
Log.Debug(info);
|
Log.Debug(info, MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ namespace Wox.Infrastructure.Storage
|
|||||||
if (File.Exists(FilePath))
|
if (File.Exists(FilePath))
|
||||||
{
|
{
|
||||||
File.Delete(FilePath);
|
File.Delete(FilePath);
|
||||||
Log.Info($"|BinaryStorage.TryLoad|Deleting cached data at <{FilePath}>");
|
|
||||||
|
Log.Info($"Deleting cached data at <{FilePath}>", GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +53,8 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
if (new FileInfo(FilePath).Length == 0)
|
if (new FileInfo(FilePath).Length == 0)
|
||||||
{
|
{
|
||||||
Log.Error($"|BinaryStorage.TryLoad|Zero length cache file <{FilePath}>");
|
Log.Error($"Zero length cache file <{FilePath}>", GetType());
|
||||||
|
|
||||||
Save(defaultData);
|
Save(defaultData);
|
||||||
return defaultData;
|
return defaultData;
|
||||||
}
|
}
|
||||||
@@ -65,7 +67,8 @@ namespace Wox.Infrastructure.Storage
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Info("|BinaryStorage.TryLoad|Cache file not exist, load default data");
|
Log.Info("Cache file not exist, load default data", GetType());
|
||||||
|
|
||||||
Save(defaultData);
|
Save(defaultData);
|
||||||
return defaultData;
|
return defaultData;
|
||||||
}
|
}
|
||||||
@@ -87,7 +90,8 @@ namespace Wox.Infrastructure.Storage
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|BinaryStorage.Deserialize|Deserialize error for file <{FilePath}>", e);
|
Log.Exception($"Deserialize error for file <{FilePath}>", e, GetType());
|
||||||
|
|
||||||
return defaultData;
|
return defaultData;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -128,12 +132,12 @@ namespace Wox.Infrastructure.Storage
|
|||||||
}
|
}
|
||||||
catch (SerializationException e)
|
catch (SerializationException e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|BinaryStorage.Save|serialize error for file <{FilePath}>", e);
|
Log.Exception($"Serialize error for file <{FilePath}>", e, GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_storageHelper.Close();
|
_storageHelper.Close();
|
||||||
Log.Info($"|BinaryStorage.Save|Saving cached data at <{FilePath}>");
|
Log.Info($"Saving cached data at <{FilePath}>", GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
if (File.Exists(FilePath))
|
if (File.Exists(FilePath))
|
||||||
{
|
{
|
||||||
File.Delete(FilePath);
|
File.Delete(FilePath);
|
||||||
Log.Info($"|JsonStorage.TryLoad|Deleting cached data at <{FilePath}>");
|
Log.Info($"Deleting cached data at <{FilePath}>", GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
catch (JsonException e)
|
catch (JsonException e)
|
||||||
{
|
{
|
||||||
LoadDefault();
|
LoadDefault();
|
||||||
Log.Exception($"|JsonStorage.Deserialize|Deserialize error for json <{FilePath}>", e);
|
Log.Exception($"Deserialize error for json <{FilePath}>", e, GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data == null)
|
if (_data == null)
|
||||||
@@ -123,11 +123,12 @@ namespace Wox.Infrastructure.Storage
|
|||||||
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
|
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
|
||||||
File.WriteAllText(FilePath, serialized);
|
File.WriteAllText(FilePath, serialized);
|
||||||
_storageHelper.Close();
|
_storageHelper.Close();
|
||||||
Log.Info($"|JsonStorage.Save|Saving cached data at <{FilePath}>");
|
|
||||||
|
Log.Info($"Saving cached data at <{FilePath}>", GetType());
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
Log.Error($"|JsonStorage.Save|Error in saving data at <{FilePath}>", e.Message);
|
Log.Exception($"Error in saving data at <{FilePath}>", e, GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
}
|
}
|
||||||
catch (ArgumentException e)
|
catch (ArgumentException e)
|
||||||
{
|
{
|
||||||
Log.Info($"|LisRepository.Set| Trying to insert a duplicate item", e.Message);
|
Log.Info($"Trying to insert a duplicate item {e.Message}", GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
if (!_items.TryAdd(insertedItem.GetHashCode(), insertedItem))
|
if (!_items.TryAdd(insertedItem.GetHashCode(), insertedItem))
|
||||||
{
|
{
|
||||||
Log.Error($"|ListRepository.Add| Item Already Exists <{insertedItem}>");
|
Log.Error($"Item Already Exists <{insertedItem}>", GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
if (!_items.TryRemove(removedItem.GetHashCode(), out _))
|
if (!_items.TryRemove(removedItem.GetHashCode(), out _))
|
||||||
{
|
{
|
||||||
Log.Error($"|ListRepository.Remove| Item Not Found <{removedItem}>");
|
Log.Error($"Item Not Found <{removedItem}>", GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace Wox.Infrastructure.UserSettings
|
|||||||
}
|
}
|
||||||
catch (ArgumentException e)
|
catch (ArgumentException e)
|
||||||
{
|
{
|
||||||
Logger.Log.Exception(nameof(Settings), "Failed to load QuerySearchPrecisionString value from Settings file", e);
|
Logger.Log.Exception("Failed to load QuerySearchPrecisionString value from Settings file", e, GetType());
|
||||||
|
|
||||||
QuerySearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
|
QuerySearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
|
||||||
StringMatcher.Instance.UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
|
StringMatcher.Instance.UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
|
||||||
|
|||||||
Reference in New Issue
Block a user