From d3face8664a1e8d37550e182901d2b7215be6f6d Mon Sep 17 00:00:00 2001 From: Den Delimarsky <1389609+dend@users.noreply.github.com> Date: Thu, 29 Apr 2021 08:18:35 -0700 Subject: [PATCH] Improved logging for better diagnostics --- .../espresso/Espresso.Shell/Core/APIHelper.cs | 19 +++++++++++++++++++ .../Espresso.Shell/Espresso.Shell.csproj | 1 + .../espresso/Espresso.Shell/Program.cs | 6 +++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/modules/espresso/Espresso.Shell/Core/APIHelper.cs b/src/modules/espresso/Espresso.Shell/Core/APIHelper.cs index 824a492e1..16f72bee5 100644 --- a/src/modules/espresso/Espresso.Shell/Core/APIHelper.cs +++ b/src/modules/espresso/Espresso.Shell/Core/APIHelper.cs @@ -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 /// 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; + } + } } } diff --git a/src/modules/espresso/Espresso.Shell/Espresso.Shell.csproj b/src/modules/espresso/Espresso.Shell/Espresso.Shell.csproj index 1fbdc1b64..04aba5643 100644 --- a/src/modules/espresso/Espresso.Shell/Espresso.Shell.csproj +++ b/src/modules/espresso/Espresso.Shell/Espresso.Shell.csproj @@ -6,6 +6,7 @@ + diff --git a/src/modules/espresso/Espresso.Shell/Program.cs b/src/modules/espresso/Espresso.Shell/Program.cs index 5be5ca592..2211dc1a5 100644 --- a/src/modules/espresso/Espresso.Shell/Program.cs +++ b/src/modules/espresso/Espresso.Shell/Program.cs @@ -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( 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}"); } }