mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Improve logging for PT Run (#6800)
* init code pass * adjusting tabbing for readabilty * few small adjustments
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Plugin.Program.Logger;
|
||||
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)
|
||||
{
|
||||
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(
|
||||
package.Id.Name,
|
||||
package.Id.FullName,
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Xml.Linq;
|
||||
@@ -80,9 +81,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
else
|
||||
{
|
||||
var e = Marshal.GetExceptionForHR((int)hResult);
|
||||
ProgramLogger.LogException(
|
||||
$"|UWP|InitializeAppInfo|{path}" +
|
||||
"|Error caused while trying to get the details of the UWP program", e);
|
||||
ProgramLogger.Exception("Error caused while trying to get the details of the UWP program", e, GetType(), path);
|
||||
|
||||
Apps = new List<UWPApplication>().ToArray();
|
||||
}
|
||||
@@ -104,7 +103,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
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>();
|
||||
}
|
||||
@@ -128,10 +127,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
ProgramLogger.LogException(
|
||||
$"|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());
|
||||
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);
|
||||
|
||||
Version = PackageVersion.Unknown;
|
||||
}
|
||||
@@ -153,9 +149,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|UWP|All|{p.InstalledLocation}|An unexpected error occurred and "
|
||||
+ $"unable to convert Package to UWP for {p.FullName}", e);
|
||||
ProgramLogger.Exception($"Unable to convert Package to UWP for {p.FullName}", e, MethodBase.GetCurrentMethod().DeclaringType, p.InstalledLocation);
|
||||
|
||||
return Array.Empty<UWPApplication>();
|
||||
}
|
||||
|
||||
@@ -190,7 +185,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
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;
|
||||
}
|
||||
},
|
||||
@@ -310,9 +310,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|UWP|ResourceFromPri|{Package.Location}|Can't load null or empty result "
|
||||
+ $"pri {source} in uwp location {Package.Location}", new NullReferenceException());
|
||||
ProgramLogger.Exception($"Can't load null or empty result pri {source} in uwp location {Package.Location}", new NullReferenceException(), GetType(), Package.Location);
|
||||
|
||||
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.BingFoodAndDrink_3.0.4.336_x64__8wekyb3d8bbwe: ms-resource:AppDescription
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -569,9 +569,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
LogoPath = string.Empty;
|
||||
LogoType = LogoType.Error;
|
||||
ProgramLogger.LogException(
|
||||
$"|UWP|LogoPathFromUri|{Package.Location}" +
|
||||
$"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException());
|
||||
ProgramLogger.Exception($"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException(), GetType(), Package.Location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,6 +587,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
private const int _dpiScale100 = 96;
|
||||
|
||||
private ImageSource PlatedImage(BitmapImage image)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(BackgroundColor))
|
||||
@@ -630,21 +630,21 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
var context = visual.RenderOpen();
|
||||
context.DrawDrawing(group);
|
||||
context.Close();
|
||||
const int dpiScale100 = 96;
|
||||
|
||||
var bitmap = new RenderTargetBitmap(
|
||||
Convert.ToInt32(width),
|
||||
Convert.ToInt32(height),
|
||||
dpiScale100,
|
||||
dpiScale100,
|
||||
_dpiScale100,
|
||||
_dpiScale100,
|
||||
PixelFormats.Pbgra32);
|
||||
|
||||
bitmap.Render(visual);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|UWP|PlatedImage|{Package.Location}|Unable to convert background string {BackgroundColor} " +
|
||||
$"to color for {Package.Location}", new InvalidOperationException());
|
||||
ProgramLogger.Exception($"Unable to convert background string {BackgroundColor} to color for {Package.Location}", new InvalidOperationException(), GetType(), Package.Location);
|
||||
|
||||
return new BitmapImage(new Uri(Constant.ErrorIcon));
|
||||
}
|
||||
@@ -674,9 +674,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|UWP|ImageFromPath|{path}|Unable to get logo for {UserModelId} from {path} and" +
|
||||
$" located in {Package.Location}", new FileNotFoundException());
|
||||
ProgramLogger.Exception($"Unable to get logo for {UserModelId} from {path} and located in {Package.Location}", new FileNotFoundException(), GetType(), path);
|
||||
return new BitmapImage(new Uri(ImageLoader.ErrorIconPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
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;
|
||||
}
|
||||
},
|
||||
@@ -351,9 +351,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|Win32Program|{path}" +
|
||||
$"|Permission denied when trying to load the program from {path}", e);
|
||||
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
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.
|
||||
// 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 };
|
||||
}
|
||||
|
||||
@@ -426,9 +424,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|InternetShortcutProgram|{path}" +
|
||||
$"|Permission denied when trying to load the program from {path}", e);
|
||||
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
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
|
||||
catch (Exception e)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|LnkProgram|{path}" +
|
||||
"|An unexpected error occurred in the calling method LnkProgram", e);
|
||||
ProgramLogger.Exception("An unexpected error occurred in the calling method LnkProgram", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
program.Valid = false;
|
||||
return program;
|
||||
@@ -501,17 +495,13 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|ExeProgram|{path}" +
|
||||
$"|Permission denied when trying to load the program from {path}", e);
|
||||
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
return new Win32Program() { Valid = false, Enabled = false };
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|ExeProgram|{path}" +
|
||||
$"|Unable to locate exe file at {path}", e);
|
||||
ProgramLogger.Exception($"|Unable to locate exe file at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
return new Win32Program() { Valid = false, Enabled = false };
|
||||
}
|
||||
@@ -619,17 +609,13 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (DirectoryNotFoundException e)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
||||
"|The directory trying to load the program from does not exist", e);
|
||||
ProgramLogger.Exception("|The directory trying to load the program from does not exist", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
||||
$"|Permission denied when trying to load programs from {currentDirectory}", e);
|
||||
ProgramLogger.Exception($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -647,9 +633,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
||||
$"|Permission denied when trying to load programs from {currentDirectory}", e);
|
||||
ProgramLogger.Exception($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
}
|
||||
while (folderQueue.Any());
|
||||
@@ -841,9 +825,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
ProgramLogger.LogException(
|
||||
$"|Win32|GetProgramPathFromRegistrySubKeys|{path}" +
|
||||
$"|Permission denied when trying to load the program from {path}", e);
|
||||
ProgramLogger.Exception($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -963,7 +945,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
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>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user