Skip to content

Commit 5552bea

Browse files
committed
Show just one error box for logger write errors
To avoid interrupting user work. Addresing #8
1 parent 079e51e commit 5552bea

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

CodeStats/Logger.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal enum LogLevel
1717
static class Logger
1818
{
1919
internal static string configDir;
20+
internal static bool hasAlreadyShownErrorBox = false;
2021

2122
internal static void Debug(string msg)
2223
{
@@ -38,7 +39,7 @@ internal static void Warning(string msg)
3839

3940
internal static void Error(string msg, Exception ex = null)
4041
{
41-
var exceptionMessage = string.Format("{0}: {1}", msg, ex);
42+
var exceptionMessage = $"{msg}: {ex}";
4243

4344
Log(LogLevel.HandledException, exceptionMessage);
4445
}
@@ -56,8 +57,12 @@ internal static void Log(LogLevel level, string msg)
5657
}
5758
catch (Exception ex)
5859
{
59-
MessageBox.Show(ex.ToString(), "Error writing to log file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
60-
//MessageBox.Show(string.Format("{0}\\{1}.log", configDir, Constants.PluginName), "Error writing to log file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
60+
if (!hasAlreadyShownErrorBox)
61+
{
62+
MessageBox.Show(ex.ToString() + "\n\nNo further log writing errors will be shown in this session to avoid interrupting your work.", "Error writing to log file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
63+
//MessageBox.Show(string.Format("{0}\\{1}.log", configDir, Constants.PluginName), "Error writing to log file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
64+
hasAlreadyShownErrorBox = true;
65+
}
6166
}
6267
}
6368

0 commit comments

Comments
 (0)