mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-11 09:49:22 +08:00
Improved logging for better diagnostics
This commit is contained in:
parent
8496b1dc09
commit
d3face8664
@ -2,6 +2,7 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Win32;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -25,6 +26,8 @@ namespace Espresso.Shell.Core
|
||||
/// </summary>
|
||||
public class APIHelper
|
||||
{
|
||||
private const string BUILD_REGISTRY_LOCATION = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
|
||||
|
||||
private static CancellationTokenSource TokenSource = new CancellationTokenSource();
|
||||
private static CancellationToken ThreadToken;
|
||||
|
||||
@ -154,5 +157,21 @@ namespace Espresso.Shell.Core
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetOperatingSystemBuild()
|
||||
{
|
||||
try
|
||||
{
|
||||
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BUILD_REGISTRY_LOCATION);
|
||||
|
||||
var versionString = $"{registryKey.GetValue("ProductName")} {registryKey.GetValue("DisplayVersion")} {registryKey.GetValue("BuildLabEx")}";
|
||||
return versionString;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Debug($"Could not get registry key for the build number. Error: {ex.Message}");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NLog" Version="4.7.9" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20071.2" />
|
||||
|
@ -42,6 +42,8 @@ namespace Espresso.Shell
|
||||
|
||||
log.Info("Launching Espresso...");
|
||||
log.Info(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion);
|
||||
log.Debug($"OS: {Environment.OSVersion}");
|
||||
log.Debug($"OS Build: {APIHelper.GetOperatingSystemBuild()}");
|
||||
|
||||
var configOption = new Option<string>(
|
||||
aliases: new[] { "--config", "-c" },
|
||||
@ -106,6 +108,7 @@ namespace Espresso.Shell
|
||||
|
||||
private static void HandleCommandLineArguments(string config, bool displayOn, long timeLimit)
|
||||
{
|
||||
log.Info($"The value for --config is: {config}");
|
||||
log.Info($"The value for --display-on is: {displayOn}");
|
||||
log.Info($"The value for --time-limit is: {timeLimit}");
|
||||
|
||||
@ -251,9 +254,10 @@ namespace Espresso.Shell
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorMessage = $"There was a problem reading the configuration file.\n{ex.Message}";
|
||||
var errorMessage = $"There was a problem reading the configuration file. Error: {ex.Message}";
|
||||
log.Info(errorMessage);
|
||||
log.Debug(errorMessage);
|
||||
log.Debug($"Configuration path: {fullPath}");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user