improve logging

This commit is contained in:
Jakob 2023-07-09 18:19:33 +02:00
parent 90fc53ce00
commit d347ccefdf
5 changed files with 65 additions and 19 deletions

View file

@ -49,7 +49,6 @@ namespace EnvyUpdate
return "Nvidia GeForce RTX 4080 (debug)";
}
[ConditionalAttribute("DEBUG")]
public static void LogToFile(string content)
{
if (isVerbose)

File diff suppressed because one or more lines are too long

View file

@ -21,6 +21,9 @@ namespace EnvyUpdate
labelVer.Content += " " + version;
if (GlobalVars.monitoringInstall)
labelVer.FontStyle = FontStyles.Italic;
if (File.Exists(Path.Combine(GlobalVars.exeloc, "envyupdate.log")))
chkLog.IsChecked = true;
}
private void ButtonWeb_Click(object sender, RoutedEventArgs e)
@ -28,5 +31,20 @@ namespace EnvyUpdate
Debug.LogToFile("INFO Launching website.");
System.Diagnostics.Process.Start("https://github.com/fyr77/EnvyUpdate/");
}
private void chkLog_Checked(object sender, RoutedEventArgs e)
{
Debug.isVerbose = true;
Debug.LogToFile("------");
Debug.LogToFile("INFO Enabled logging to file. Restart Application to see full startup log.");
}
private void chkLog_Unchecked(object sender, RoutedEventArgs e)
{
Debug.LogToFile("INFO Disabled logging to file.");
if (File.Exists(Path.Combine(GlobalVars.exeloc, "envyupdate.log")))
File.Move(Path.Combine(GlobalVars.exeloc, "envyupdate.log"), Path.Combine(GlobalVars.exeloc, "envyupdate.old.log"));
Debug.isVerbose = false;
}
}
}

View file

@ -37,11 +37,16 @@ namespace EnvyUpdate
// This is necessary, since .NET throws an exception if you check for a non-existant arg.
}
if (Debug.isVerbose)
// Check if Debug file exists
if (File.Exists(Path.Combine(GlobalVars.exedirectory, "envyupdate.log")))
{
File.AppendAllText(Debug.debugFile, "INFO Starting EnvyUpdate, version " + System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion);
Debug.isVerbose = true;
Debug.LogToFile("------");
Debug.LogToFile("INFO Found log file, will start logging to this.");
}
Debug.LogToFile("INFO Starting EnvyUpdate, version " + System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion);
// Check if EnvyUpdate is already running
if (Util.IsInstanceOpen("EnvyUpdate"))
{
@ -95,7 +100,7 @@ namespace EnvyUpdate
else
textblockLocalType.Text = "Standard";
Debug.LogToFile("INFO Done detecting driver type.");
Debug.LogToFile("INFO Done detecting driver type: " + textblockLocalType.Text);
// Check for startup shortcut
if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk")))
@ -189,7 +194,7 @@ namespace EnvyUpdate
}
catch (ArgumentException)
{
Debug.LogToFile("WARN Could not get GPU update URL, trying again with standard driver.");
Debug.LogToFile("WARN Could not get GPU update URL, trying again with non-studio driver.");
try
{
// disable SD and try with GRD
@ -202,6 +207,11 @@ namespace EnvyUpdate
MessageBox.Show(Properties.Resources.ui_studionotsupported);
radioGRD.IsChecked = true;
}
catch (ArgumentNullException)
{
MessageBox.Show("ERROR: Could not get list of GPU models from Nvidia, please check your network connection.\nOtherwise, please report this issue on GitHub.");
Environment.Exit(11);
}
catch (ArgumentException e)
{
// Now we have a problem.

View file

@ -132,7 +132,7 @@ namespace EnvyUpdate
Environment.Exit(2);
}
public static int GetIDs(string IDtype)
public static int GetIDs(string IDtype, bool retry = true)
{
string xmlcontent = null;
int id = -1;
@ -154,7 +154,6 @@ namespace EnvyUpdate
Debug.LogToFile("INFO Got Nvidia GPU list.");
if (xmlcontent == null)
{
Debug.LogToFile("WARN GPU list is NULL! This is a possible error source.");
switch (IDtype)
{
case "osid":
@ -162,8 +161,22 @@ namespace EnvyUpdate
Debug.LogToFile("WARN Ignore previous warning, just getting osid.");
Debug.LogToFile("INFO Got osid: " + id);
break;
case "psid":
case "pfid":
Debug.LogToFile("WARN GPU list is NULL! This is a possible error source.");
if (retry)
{
Debug.LogToFile("WARN Trying to get ID again.");
id = GetIDs(IDtype, false);
}
else
{
Debug.LogToFile("FATAL Could not get GPU list to find IDs.");
throw new ArgumentNullException();
}
break;
default:
Debug.LogToFile("WARN GetIDs was called, but nothing was specified.");
Debug.LogToFile("WARN GetIDs was called, but nothing was specified. THIS SHOULD NOT HAPPEN!");
break;
}
}
@ -224,7 +237,7 @@ namespace EnvyUpdate
}
else
{
Debug.LogToFile("DEBUG Getting something else than psid.");
Debug.LogToFile("DEBUG Getting something other than psid.");
string result = name.Parent.Value.ToLower();
int index = result.IndexOf(sName);