Skip to content

Commit 2525c46

Browse files
committed
Rewrite logging events
More simplified and consistent wording, assisted in large parts by Copilot.
1 parent 0f08773 commit 2525c46

7 files changed

Lines changed: 125 additions & 126 deletions

File tree

src/ShutdownTimer/Countdown.cs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,29 @@ public void ExitExternal()
4545
// entrypoint
4646
private void Countdown_Load(object sender, EventArgs e)
4747
{
48-
ExceptionHandler.Log("Checking multiple instances configuration");
48+
ExceptionHandler.Log("Check multiple instances setting");
4949

5050
if (!SettingsProvider.Settings.EnableMultipleInstances)
5151
{
52-
ExceptionHandler.Log("Multiple instances are not allowed");
52+
ExceptionHandler.Log("Multiple instances disabled");
5353

54-
ExceptionHandler.Log("Checking for another instance already running");
54+
ExceptionHandler.Log("Checking for running instance");
5555
if (!ApplicationInstanceManager.IsSingleInstance())
5656
{
5757
MessageBox.Show("Another instance of this application is already running. To allow multiple instances, please check the \"Allow multiple instances\" option in the application settings.\n\nExiting...", "Application already running!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
58-
ExceptionHandler.Log("Detected another instance already running. Exiting...");
58+
ExceptionHandler.Log("Another instance detected; exiting");
5959
Application.Exit();
6060
}
6161
}
6262
else
6363
{
64-
ExceptionHandler.Log("Multiple instances are allowed");
64+
ExceptionHandler.Log("Multiple instances allowed");
6565
}
6666

67-
ExceptionHandler.Log("Starting stopwatch");
67+
ExceptionHandler.Log("Starting timer clock");
6868
Timer.Start();
6969

70-
ExceptionHandler.Log("Preparing UI...");
70+
ExceptionHandler.Log("Preparing UI");
7171

7272
// Set custom background color / transparency
7373

@@ -98,7 +98,7 @@ private void Countdown_Load(object sender, EventArgs e)
9898
// Load password and set the lock state
9999
if (!String.IsNullOrEmpty(Password))
100100
{
101-
ExceptionHandler.Log("A password has been detected");
101+
ExceptionHandler.Log("Password configured");
102102
ChangeLockState("locked");
103103
}
104104

@@ -142,12 +142,12 @@ private void Countdown_Load(object sender, EventArgs e)
142142
this.Location = new Point(SettingsProvider.Settings.LastScreenPositionCountdown.X, SettingsProvider.Settings.LastScreenPositionCountdown.Y);
143143
}
144144

145-
ExceptionHandler.Log("Prepared UI");
145+
ExceptionHandler.Log("UI prepared");
146146

147147
ExceptionHandler.Log("Updating UI");
148148
UpdateUI(Timer.CountdownTimeSpan);
149149

150-
ExceptionHandler.Log("Entering countdown sequence...");
150+
ExceptionHandler.Log("Countdown sequence started");
151151
}
152152

153153
/// <summary>
@@ -174,7 +174,7 @@ private void Countdown_SizeChanged(object sender, EventArgs e)
174174
/// </summary>
175175
private void LockStatePictureBox_Click(object sender, EventArgs e)
176176
{
177-
ExceptionHandler.Log("User clicked on the lock icon");
177+
ExceptionHandler.Log("Lock icon clicked");
178178

179179
switch (lockState)
180180
{
@@ -183,19 +183,19 @@ private void LockStatePictureBox_Click(object sender, EventArgs e)
183183
break;
184184

185185
case 1: // lock state 'locked': ask user for password to unlock
186-
ExceptionHandler.Log("lockState = locked, requesting password for unlock from user");
186+
ExceptionHandler.Log("LockState=locked: requesting password");
187187
UnlockUIByPassword();
188188
break;
189189

190190
case 2: // lock state 'unlocked': change lockstate to 'locked'
191-
ExceptionHandler.Log("lockState = unlocked, asking user for confirmation to lock the UI");
191+
ExceptionHandler.Log("LockState=unlocked: confirming re-lock");
192192
DialogResult result = MessageBox.Show("Would you like to re-lock the countdown?", "Password Protection", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
193193
if (result == DialogResult.Yes)
194194
{
195-
ExceptionHandler.Log("User wanted to lock the UI");
195+
ExceptionHandler.Log("User confirmed lock");
196196
ChangeLockState("locked");
197197
}
198-
else { ExceptionHandler.Log("User wanted to keep the UI unlocked"); }
198+
else { ExceptionHandler.Log("User kept UI unlocked"); }
199199
break;
200200
}
201201
}
@@ -205,7 +205,7 @@ private void LockStatePictureBox_Click(object sender, EventArgs e)
205205
/// </summary>
206206
private void SaveSettings()
207207
{
208-
ExceptionHandler.Log("Saving settings...");
208+
ExceptionHandler.Log("Saving settings");
209209

210210
// Only store last screen position if setting is enabled and countdown is not in background
211211
if (SettingsProvider.Settings.RememberLastScreenPositionCountdown && IsForegroundUI)
@@ -227,31 +227,31 @@ private void SaveSettings()
227227
/// </summary>
228228
private void Countdown_FormClosing(object sender, FormClosingEventArgs e)
229229
{
230-
ExceptionHandler.Log("FormClosing event triggered");
230+
ExceptionHandler.Log("Form closing event");
231231
if (ignoreClose) // Ignore closing event
232232
{
233233
e.Cancel = true;
234-
ExceptionHandler.Log("Ignoring the close event due to ignoreClose");
234+
ExceptionHandler.Log("Close ignored (ignoreClose)");
235235
return;
236236
}
237237
else if (!allowClose && !SettingsProvider.Settings.DisableNotifications) // Ask user for confirmation
238238
{
239239
e.Cancel = true;
240-
ExceptionHandler.Log("Asking user for confirmation to exit and cancel the timer");
240+
ExceptionHandler.Log("Prompting user to confirm exit");
241241
string caption = "Are you sure?";
242242
string message = "Do you really want to cancel the timer?";
243243
DialogResult question = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
244-
if (question == DialogResult.Yes) { ExceptionHandler.Log("User wanted to exit"); ExitApplication(); return; }
244+
if (question == DialogResult.Yes) { ExceptionHandler.Log("User confirmed exit"); ExitApplication(); return; }
245245
}
246246
else if (!allowClose) // Just close without asking first, as user has disabled confirmations in settings
247247
{
248248
e.Cancel = true;
249-
ExceptionHandler.Log("Exiting without asking user as defined per DisableNotifications-setting");
249+
ExceptionHandler.Log("Exiting without confirmation (DisableNotifications=true)");
250250
ExitApplication();
251251
return;
252252
}
253253
// allowClose == true is not handled and if ignoreClose == false, the application will exit
254-
ExceptionHandler.Log("Form now closing");
254+
ExceptionHandler.Log("Form closing");
255255
//ExceptionHandler.CreateAutoLogIfApplicable();
256256
}
257257

@@ -265,26 +265,26 @@ private void Countdown_FormClosing(object sender, FormClosingEventArgs e)
265265
/// </summary>
266266
private void ExitApplication()
267267
{
268-
ExceptionHandler.Log("Trying to exit the application");
268+
ExceptionHandler.Log("Exit requested");
269269

270270
if (lockState == 1)
271271
{
272-
ExceptionHandler.Log("Attempt halted due to password protection");
273-
if (UnlockUIByPassword(true)) { ExceptionHandler.Log("Password protection passed, restarting exit sequence..."); ExitApplication(); }
272+
ExceptionHandler.Log("Exit halted by password protection");
273+
if (UnlockUIByPassword(true)) { ExceptionHandler.Log("Password accepted; resuming exit"); ExitApplication(); }
274274
}
275275
else
276276
{
277-
ExceptionHandler.Log("Exiting application...");
277+
ExceptionHandler.Log("Exiting application");
278278

279279
ignoreClose = false;
280280
allowClose = true;
281-
ExceptionHandler.Log("Stopping timer");
281+
ExceptionHandler.Log("Pausing timer");
282282
Timer.Pause();
283-
ExceptionHandler.Log("Confirming application halt to user");
283+
ExceptionHandler.Log("Sending cancellation notification");
284284
SendNotification("Your timer was canceled successfully!\nThe application will now close."); // Show windows toast notification as confirmation
285-
ExceptionHandler.Log("Saving all settings");
285+
ExceptionHandler.Log("Saving settings");
286286
SaveSettings();
287-
ExceptionHandler.Log("Exiting...");
287+
ExceptionHandler.Log("Exit");
288288
Application.Exit();
289289
}
290290
}
@@ -294,25 +294,25 @@ private void ExitApplication()
294294
/// </summary>
295295
private void RestartApplication()
296296
{
297-
ExceptionHandler.Log("Trying to restart the application");
297+
ExceptionHandler.Log("Restart requested");
298298
if (lockState == 1)
299299
{
300-
ExceptionHandler.Log("Attempt canceled due to password protection");
301-
if (UnlockUIByPassword(true)) { ExceptionHandler.Log("Password protection passed, restarting restart sequence..."); RestartApplication(); }
300+
ExceptionHandler.Log("Restart halted by password protection");
301+
if (UnlockUIByPassword(true)) { ExceptionHandler.Log("Password accepted; resuming restart"); RestartApplication(); }
302302
}
303303
else
304304
{
305-
ExceptionHandler.Log("Restarting application...");
305+
ExceptionHandler.Log("Restarting application");
306306

307307
ignoreClose = false;
308308
allowClose = true;
309-
ExceptionHandler.Log("Stopping timer");
309+
ExceptionHandler.Log("Pausing timer");
310310
Timer.Pause();
311311
ExceptionHandler.Log("Clearing EXECUTION_STATE flags");
312312
ExecutionState.SetThreadExecutionState(ExecutionState.EXECUTION_STATE.ES_CONTINUOUS); // Clear EXECUTION_STATE flags to allow the system to go to sleep if it's tired
313-
ExceptionHandler.Log("Saving all settings");
313+
ExceptionHandler.Log("Saving settings");
314314
SaveSettings();
315-
ExceptionHandler.Log("Restarting...");
315+
ExceptionHandler.Log("Restart");
316316
Application.Restart();
317317
}
318318
}
@@ -323,17 +323,17 @@ private void RestartApplication()
323323
private void ResetTimer()
324324
{
325325

326-
ExceptionHandler.Log("Trying to reset the timer");
326+
ExceptionHandler.Log("Reset requested");
327327
if (lockState == 1)
328328
{
329-
ExceptionHandler.Log("Attempt canceled due to password protection");
330-
if (UnlockUIByPassword(true)) { ExceptionHandler.Log("Password protection disabled, restarting timer reset sequence..."); ResetTimer(); }
329+
ExceptionHandler.Log("Reset halted by password protection");
330+
if (UnlockUIByPassword(true)) { ExceptionHandler.Log("Password accepted; resuming reset"); ResetTimer(); }
331331
}
332332
else
333333
{
334-
ExceptionHandler.Log("Resetting clock");
334+
ExceptionHandler.Log("Resetting timer");
335335
Timer.Reset();
336-
ExceptionHandler.Log("Updating UI");
336+
ExceptionHandler.Log("Update UI");
337337
UpdateUI(Timer.CountdownTimeSpan);
338338
if (this.WindowState == FormWindowState.Minimized) { SendNotification("Timer has been reset. Remaining time until power action will be executed is " + Timer.CountdownTimeSpan.Hours + " hours, " + Timer.CountdownTimeSpan.Minutes + " minutes and " + Timer.CountdownTimeSpan.Seconds + " seconds."); }
339339
}
@@ -363,7 +363,7 @@ private void PauseResumeTimer()
363363
/// </summary>
364364
private void ShowSetNewCountdownDialog()
365365
{
366-
ExceptionHandler.Log("User requested to set a new countdown");
366+
ExceptionHandler.Log("Prompting for new countdown time");
367367
using (var form = new InputBox())
368368
{
369369
form.Title = "Set a new countdown";
@@ -377,12 +377,12 @@ private void ShowSetNewCountdownDialog()
377377
}
378378
else if (form.ReturnValue == "" || form.ReturnValue == null)
379379
{
380-
ExceptionHandler.Log("Countdown update aborted due to no input");
380+
ExceptionHandler.Log("Update aborted: no input");
381381
MessageBox.Show("Operation aborted: You have not supplied a new time value!", "Countdown Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
382382
}
383383
else
384384
{
385-
ExceptionHandler.Log("Parsing supplied input");
385+
ExceptionHandler.Log("Parsing new time input");
386386
try
387387
{
388388
String[] values = form.ReturnValue.Split(':');
@@ -393,7 +393,7 @@ private void ShowSetNewCountdownDialog()
393393
Timer.CountdownTimeSpan = new TimeSpan(newHours, newMinutes, 0);
394394
Timer.Reset();
395395

396-
ExceptionHandler.Log("Countdown updated using HH:mm");
396+
ExceptionHandler.Log("Countdown updated (HH:mm)");
397397
}
398398
else if (values.Length == 3) // HH:mm:ss
399399
{
@@ -403,17 +403,17 @@ private void ShowSetNewCountdownDialog()
403403
Timer.CountdownTimeSpan = new TimeSpan(newHours, newMinutes, newSeconds);
404404
Timer.Reset();
405405

406-
ExceptionHandler.Log("Countdown updated using HH:mm:ss");
406+
ExceptionHandler.Log("Countdown updated (HH:mm:ss)");
407407
}
408408
else
409409
{
410-
ExceptionHandler.Log("Countdown update aborted due to malformed input");
410+
ExceptionHandler.Log("Update aborted: malformed input");
411411
MessageBox.Show("Operation aborted: You have not supplied a valid time value!", "Countdown Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
412412
}
413413
}
414414
catch (Exception)
415415
{
416-
ExceptionHandler.Log("Countdown update aborted due to error in input processing");
416+
ExceptionHandler.Log("Update aborted: input processing error");
417417
MessageBox.Show("Operation aborted: You have either not supplied a valid time value or there was an internal error outside the scope of your input while processing it.", "Countdown Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
418418
}
419419
}

src/ShutdownTimer/Helpers/ArgProcessor.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ public static class ArgProcessor
1919

2020
public static void ProcessArgs(string[] args)
2121
{
22-
ExceptionHandler.Log("Processing args...");
22+
ExceptionHandler.Log("Processing CLI args");
2323
ReadArgs(args);
2424
ExportTimeToInt();
2525
CalculateTimeSpan();
26-
ExceptionHandler.Log("Processed args");
26+
ExceptionHandler.Log("CLI args processed");
2727
}
2828

2929
private static void ReadArgs(string[] args)
3030
{
31-
ExceptionHandler.Log("Reading args...");
31+
ExceptionHandler.Log("Reading CLI args");
3232

3333
// Control Modes:
3434
// Prefill: Prefills settings but lets the user manually change them too. Timer won't start automatically.
@@ -76,12 +76,12 @@ private static void ReadArgs(string[] args)
7676
}
7777
}
7878

79-
ExceptionHandler.Log("Read args");
79+
ExceptionHandler.Log("Args read");
8080
}
8181

8282
private static void ExportTimeToInt()
8383
{
84-
ExceptionHandler.Log("Exporting to Int...");
84+
ExceptionHandler.Log("Parsing time argument");
8585

8686
if (!string.IsNullOrWhiteSpace(argTime))
8787
{
@@ -97,7 +97,7 @@ private static void ExportTimeToInt()
9797
switch (count)
9898
{
9999
case 0:
100-
ExceptionHandler.Log("Invalid time args.");
100+
ExceptionHandler.Log("Invalid time argument");
101101
break;
102102

103103
case 1:
@@ -116,12 +116,12 @@ private static void ExportTimeToInt()
116116
}
117117
}
118118

119-
ExceptionHandler.Log("Exported to Int");
119+
ExceptionHandler.Log("Time argument parsed");
120120
}
121121

122122
private static void CalculateTimeSpan()
123123
{
124-
ExceptionHandler.Log("Calculating TimeSpan...");
124+
ExceptionHandler.Log("Calculating TimeSpan");
125125

126126
argTimeTS = Numerics.CalculateCountdownTimeSpan(argTimeH, argTimeM, argTimeS, argUseTimeOfDay);
127127
}

src/ShutdownTimer/Helpers/ExitWindows.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static extern int LookupPrivilegeValue(string lpSystemName,
6262

6363
private static void GetPrivileges()
6464
{
65-
ExceptionHandler.Log("Getting privileges...");
65+
ExceptionHandler.Log("Getting privileges");
6666
TOKEN_PRIVILEGES tkp;
6767
OpenProcessToken(Process.GetCurrentProcess().Handle,
6868
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out IntPtr hToken);
@@ -78,7 +78,7 @@ private static void GetPrivileges()
7878
public static void Shutdown(bool force)
7979
{
8080
GetPrivileges();
81-
ExceptionHandler.Log("Shutting down...");
81+
ExceptionHandler.Log("Initiating shutdown");
8282
ExitWindowsEx(EWX_SHUTDOWN |
8383
(uint)(force ? (SettingsProvider.Settings.ForceIfHungFlag ? EWX_FORCEIFHUNG : EWX_FORCE) : 0) | EWX_POWEROFF, SHTDN_REASON_FLAG_PLANNED);
8484
}
@@ -87,7 +87,7 @@ public static void Shutdown(bool force)
8787
public static void Reboot(bool force)
8888
{
8989
GetPrivileges();
90-
ExceptionHandler.Log("Rebooting...");
90+
ExceptionHandler.Log("Initiating reboot");
9191
ExitWindowsEx(EWX_REBOOT |
9292
(uint)(force ? (SettingsProvider.Settings.ForceIfHungFlag ? EWX_FORCEIFHUNG : EWX_FORCE) : 0), SHTDN_REASON_FLAG_PLANNED);
9393
}
@@ -96,7 +96,7 @@ public static void Reboot(bool force)
9696
public static void LogOff(bool force)
9797
{
9898
GetPrivileges();
99-
ExceptionHandler.Log("Logging off...");
99+
ExceptionHandler.Log("Initiating logoff");
100100
ExitWindowsEx(EWX_LOGOFF |
101101
(uint)(force ? (SettingsProvider.Settings.ForceIfHungFlag ? EWX_FORCEIFHUNG : EWX_FORCE) : 0), SHTDN_REASON_FLAG_PLANNED);
102102
}
@@ -107,14 +107,14 @@ public static void LogOff(bool force)
107107

108108
public static void Lock()
109109
{
110-
ExceptionHandler.Log("Trying to lock...");
110+
ExceptionHandler.Log("Initiating workstation lock");
111111

112112
bool result = LockWorkStation();
113113

114114
if (result == false)
115115
{
116116
// An error occurred
117-
ExceptionHandler.Log("Error locking workstation!");
117+
ExceptionHandler.Log("Failed to lock workstation");
118118
throw new Win32Exception(Marshal.GetLastWin32Error());
119119
}
120120
else { ExceptionHandler.Log("Workstation lock successful"); }

0 commit comments

Comments
 (0)