-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (63 loc) · 2.45 KB
/
Copy pathProgram.cs
File metadata and controls
80 lines (63 loc) · 2.45 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
72
73
74
75
76
77
78
79
80
using Avalonia;
using Serilog;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace SmartFoldering
{
internal class Program
{
private static Mutex _mutex = null;
[STAThread]
public static void Main(string[] args)
{
string logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SmartFoldering", "Logs");
string logPath = Path.Combine(logDirectory, "log-.txt");
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File(logPath, rollingInterval: RollingInterval.Day)
.CreateLogger();
try
{
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
Log.Fatal(e.ExceptionObject as Exception, "A critical error has occurred and was caught at the application boundaries!");
};
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
Log.Error(e.Exception, "An unobserved Task error has occurred!");
e.SetObserved();
};
const string appName = "SmartFoldering_UniqueAppKey_2023";
_mutex = new Mutex(true, appName, out bool createdNew);
if (!createdNew)
{
Log.Warning("Another instance of the app is already running. A second instance has been blocked.");
return;
}
Log.Information("SmartFoldering is starting...");
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
catch (Exception ex)
{
Log.Fatal(ex, "The app has unexpectedly closed!");
}
finally
{
Log.Information("SmartFoldering is shutting down...");
Log.CloseAndFlush();
if (_mutex != null)
{
_mutex.ReleaseMutex();
_mutex.Dispose();
}
}
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}