Applied logging to program.cs

Continued to apply logging to the
various software components so that
we can get debugging logs when the
software is released for use.
This commit is contained in:
Terry MacDonald 2021-02-14 09:18:49 +13:00
parent dd8939b395
commit 24c1ff29b4

View File

@ -293,6 +293,7 @@ namespace DisplayMagician {
private static void CreateProfile() private static void CreateProfile()
{ {
logger.Debug($"Program/CreateProfile: Starting");
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
@ -328,7 +329,7 @@ namespace DisplayMagician {
private static void StartUpApplication() private static void StartUpApplication()
{ {
logger.Debug($"Program/StartUpApplication: Starting");
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
@ -428,6 +429,8 @@ namespace DisplayMagician {
// ReSharper disable once CyclomaticComplexity // ReSharper disable once CyclomaticComplexity
private static void RunShortcut(string shortcutUUID) private static void RunShortcut(string shortcutUUID)
{ {
logger.Debug($"Program/RunShortcut: Starting");
ShortcutItem shortcutToRun = null; ShortcutItem shortcutToRun = null;
// Check there is only one version of this application so we won't // Check there is only one version of this application so we won't
@ -479,14 +482,22 @@ namespace DisplayMagician {
// ApplyProfile lives here so that the UI works. // ApplyProfile lives here so that the UI works.
public static bool ApplyProfile(ProfileItem profile) public static bool ApplyProfile(ProfileItem profile)
{ {
logger.Debug($"Program/ApplyProfile: Starting");
// We need to check if the profile is valid // We need to check if the profile is valid
if (!profile.IsPossible) if (!profile.IsPossible)
{
logger.Debug($"Program/ApplyProfile: The supplied profile {profile.Name} isn't currently possible to use, so we can't apply it. This means a display that existed before has been removed, or moved.");
return false; return false;
}
// We need to check if the profile is the same one that we're on // We need to check if the profile is the same one that we're on
if (profile.IsActive) if (profile.IsActive)
{
logger.Debug($"Program/ApplyProfile: The supplied profile {profile.Name} is currently in use, so we don't need to apply it.");
return false; return false;
}
try try
{ {
@ -529,15 +540,25 @@ namespace DisplayMagician {
.Where(topology => topology != null) .Where(topology => topology != null)
.Select(topology => topology.ToGridTopology()) .Select(topology => topology.ToGridTopology())
.Count(); .Count();
if (toProfileSurroundTopologyCount > 0)
logger.Debug($"Program/ApplyProfile: {profile.Name} profile we want to use is a NVIDIA Surround profile, so we need to change the NVIDIA GRID topology.");
else
logger.Debug($"Program/ApplyProfile: {profile.Name} profile we want to use does not use NVIDIA Surround.");
int fromProfileSurroundTopologyCount = int fromProfileSurroundTopologyCount =
ProfileRepository.CurrentProfile.Paths.SelectMany(paths => paths.TargetDisplays) ProfileRepository.CurrentProfile.Paths.SelectMany(paths => paths.TargetDisplays)
.Select(target => target.SurroundTopology) .Select(target => target.SurroundTopology)
.Where(topology => topology != null) .Where(topology => topology != null)
.Select(topology => topology.ToGridTopology()) .Select(topology => topology.ToGridTopology())
.Count(); .Count();
if (fromProfileSurroundTopologyCount > 0)
logger.Debug($"Program/ApplyProfile: {ProfileRepository.CurrentProfile} profile currently in use is a NVIDIA Surround profile, so we need to change the NVIDIA GRID topology.");
else
logger.Debug($"Program/ApplyProfile: {ProfileRepository.CurrentProfile} profile currently in use does not use NVIDIA Surround.");
if (toProfileSurroundTopologyCount > 0 || fromProfileSurroundTopologyCount > 0) if (toProfileSurroundTopologyCount > 0 || fromProfileSurroundTopologyCount > 0)
{ {
logger.Debug($"Program/ApplyProfile: Changing the NVIDIA GRID topology to apply or remove a NVIDIA Surround profile");
topologyForm.ShowDialog(); topologyForm.ShowDialog();
try try
@ -566,10 +587,14 @@ namespace DisplayMagician {
Console.WriteLine("Program/ApplyProfile : Applying Profile Topology stage failed to complete"); Console.WriteLine("Program/ApplyProfile : Applying Profile Topology stage failed to complete");
if (!applyTopologyTask.IsCompleted) if (!applyTopologyTask.IsCompleted)
{
logger.Debug($"Program/ApplyProfile: Failed to complete applying or removing the NVIDIA Surround profile");
return false; return false;
}
} }
// We always want to do the WindowsDisplayAPI PathInfo part // We always want to do the WindowsDisplayAPI PathInfo part
logger.Debug($"Program/ApplyProfile: Changing the Windows Display Path Info to change the Windows Display layout");
pathInfoForm.ShowDialog(); pathInfoForm.ShowDialog();
try try
{ {
@ -594,7 +619,7 @@ namespace DisplayMagician {
} }
if (applyPathInfoTask.IsFaulted) if (applyPathInfoTask.IsFaulted)
Console.WriteLine("Program/ApplyProfile : Applying Profile PathInfo stage failed to complete"); logger.Debug($"Program/ApplyProfile: Applying Profile PathInfo stage failed to complete");
if (!applyPathInfoTask.IsCompleted) if (!applyPathInfoTask.IsCompleted)
return false; return false;
@ -603,7 +628,10 @@ namespace DisplayMagician {
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"ProfileRepository/ApplyTopology exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); Console.WriteLine($"ProfileRepository/ApplyTopology exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
return false; {
logger.Debug($"Program/ApplyProfile: Failed to complete changing the Windows Display layout");
return false;
}
} }
return true; return true;
@ -701,13 +729,11 @@ namespace DisplayMagician {
bool failedTask = false; bool failedTask = false;
foreach (var loadGameTask in loadGamesTasks) foreach (var loadGameTask in loadGamesTasks)
{ {
Console.WriteLine($"Program/LoadGamesInBackground: LoadGameTask #{loadGameTask.Id}: {loadGameTask.Status}");
if (loadGameTask.Exception != null) if (loadGameTask.Exception != null)
{ {
failedTask = true; failedTask = true;
foreach (var ex in loadGameTask.Exception.InnerExceptions) foreach (var ex in loadGameTask.Exception.InnerExceptions)
Console.WriteLine(" {0}: {1}", ex.GetType().Name, logger.Error(ex, $"Program/LoadGamesInBackground exception during loadGamesTasks");
ex.Message);
} }
} }