mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Add log for cmd pal ext to trace exceptions (#39326)
* Add log to trace error for apps. * Add bookmark log * registry exception log * fix * Added logger for cmdpal extensions. Signed-off-by: Shawn Yuan <shuaiyuan@microsoft.com> * remove noise * Update Signed-off-by: Shawn Yuan <shuaiyuan@microsoft.com> * change log level * change level * Fix comments * Fixed comments. Signed-off-by: Shawn Yuan <shuaiyuan@microsoft.com> * Resolve comments Signed-off-by: Shawn Yuan <shuaiyuan@microsoft.com> --------- Signed-off-by: Shawn Yuan <shuaiyuan@microsoft.com> Co-authored-by: Shawn Yuan <shuaiyuan@microsoft.com>
This commit is contained in:
@@ -8,6 +8,7 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.WindowsServices.Commands;
|
||||
using Microsoft.CmdPal.Ext.WindowsServices.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
@@ -147,12 +148,14 @@ public static class ServiceHelper
|
||||
// TODO GH #108 We need to figure out some logging
|
||||
// contextAPI.ShowNotification(GetLocalizedErrorMessage(action), serviceResult.DisplayName);
|
||||
// Log.Error($"The command returned {exitCode}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||
Logger.LogError($"The command returned {exitCode}");
|
||||
}
|
||||
}
|
||||
catch (Win32Exception ex)
|
||||
{
|
||||
// TODO GH #108 We need to figure out some logging
|
||||
// Log.Error(ex.Message, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
Logger.LogError($"Failed to change service '{serviceResult.DisplayName}' status to {action}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0059, CS0168, SA1005
|
||||
@@ -173,6 +176,7 @@ public static class ServiceHelper
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO GH #108 We need to figure out some logging
|
||||
Logger.LogError($"Failed to open services.msc: {ex.Message}");
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0059, CS0168, SA1005
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.ServiceProcess;
|
||||
using ManagedCommon;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.WindowsServices;
|
||||
|
||||
@@ -35,10 +36,11 @@ public class ServiceResult
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// try to log the exception in the future
|
||||
// retrieve properties from serviceController will throw exception. Such as PlatformNotSupportedException.
|
||||
Logger.LogError($"Failed to create ServiceController: {ex.GetType().Name} - {ex.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user