Improved logging for better diagnostics

This commit is contained in:
Den Delimarsky 2021-04-29 08:18:35 -07:00
parent 8496b1dc09
commit d3face8664
No known key found for this signature in database
GPG key ID: E1BE1355085F0BCF
3 changed files with 25 additions and 1 deletions

View file

@ -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;
}
}
}
}

View file

@ -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" />

View file

@ -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}");
}
}