-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (66 loc) · 2.12 KB
/
Program.cs
File metadata and controls
71 lines (66 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Diagnostics;
using NLog;
namespace FileDateTime_Manipulator
{
/// <summary>
/// Main class of the program.
/// </summary>
internal static class Program
{
/// <summary>
/// Logger instance for logging messages and exceptions.
/// </summary>
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
{
try
{
// Initializes the application configurations
ApplicationConfiguration.Initialize();
Logger.Info(message: "Application started.");
// Starts the main form of the application
using FdtmForm mainForm = new();
Application.Run(mainForm: mainForm);
}
catch (InvalidOperationException ex)
{
// Handle specific InvalidOperationException
const string message = "An invalid operation occurred. Please try again.";
Debug.WriteLine(value: ex);
Logger.Error(exception: ex, message: message);
LogError(ex: ex);
ShowErrorMessage(message: message);
}
catch (Exception ex)
{
// Error handling: Log the error and display an error message
const string message = "An unexpected error occurred. Please contact support.";
Debug.WriteLine(value: ex);
Logger.Error(exception: ex, message: message);
LogError(ex: ex);
ShowErrorMessage(message: message);
}
}
/// <summary>
/// Logs the error details to the console or a logging system.
/// </summary>
/// <param name="ex">The exception to log.</param>
private static void LogError(Exception ex)
{
// Implement logging logic here (e.g., log to a file or monitoring system)
Console.WriteLine(value: $@"Error: {ex.Message} {ex.StackTrace}");
}
/// <summary>
/// Displays an error message to the user.
/// </summary>
/// <param name="message">The error message to display.</param>
private static void ShowErrorMessage(string message)
{
_ = MessageBox.Show(text: message, caption: @"Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
}
}
}