Skip to content

Commit

Permalink
Print unhandled exceptions to the terminal if in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Nov 17, 2024
1 parent 23bb44a commit 5041d89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cli/ExceptionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public static class ExceptionLogger
{
public static void Log(Exception ex)
{
#if DEBUG
Console.WriteLine("Unexpected exception caught:");
Console.WriteLine(ex);
#else
var logDirectoryPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"elk/logs"
Expand All @@ -17,5 +21,6 @@ public static void Log(Exception ex)
var logFilePath = Path.Combine(logDirectoryPath, $"exception-{date}.txt");
File.WriteAllText(logFilePath, ex.ToString());
Console.WriteLine($"Unexpected exception caught! This is a bug. Log written to: {logFilePath}");
#endif
}
}
4 changes: 2 additions & 2 deletions cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@
catch (Exception ex)
{
ExceptionLogger.Log(ex);
Console.WriteLine("Press any key to continue");
Console.ReadKey();
}
}

return;
}

var session = new ShellSession(
Expand Down

0 comments on commit 5041d89

Please sign in to comment.