This repository was archived by the owner on Nov 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (101 loc) · 3.39 KB
/
Program.cs
File metadata and controls
110 lines (101 loc) · 3.39 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using ADB.CMD;
using CommandLine;
using System;
using System.Reflection;
using System.Linq;
using Serilog;
using System.IO;
/// <summary>
/// Aves Dependency Builder
/// </summary>
namespace ADB
{
/// <summary>
/// Main entry point
/// </summary>
public static class Program
{
static void Main(string[] args)
{
Run(args);
}
public static void Run(string[] args)
{
Serilog.Log.Logger = GetDefaultLoggerConfiguration().CreateLogger();
AppDomain.CurrentDomain.ProcessExit += (s, ev) =>
{
Log.Info("Shutting down logger; Flushing...");
Serilog.Log.CloseAndFlush();
};
#if !DEBUG
AppDomain.CurrentDomain.UnhandledException += (s, ev) =>
{
try
{
if (ev?.ExceptionObject is Exception ex)
{
Log.Fatal("An unhandled error occured", ex);
return;
}
Log.Fatal($"An unhandled error occured {ev}");
}
catch (Exception ex)
{
Console.Error.WriteLine($"Failed to catch unhandled error '{ev?.ExceptionObject ?? ev}': {ex}");
}
};
try
{
#endif
Parser.Default.ParseArguments<CmdOption>(args)
.WithParsed((opt) =>
{
if (opt.ShowVersion)
{
Console.WriteLine($"{Assembly.GetExecutingAssembly().GetName().Name} {Assembly.GetExecutingAssembly().GetName().Version}");
return;
}
if (opt.LogToFile)
{
var logConf = GetDefaultLoggerConfiguration();
logConf.WriteTo.File(Path.Combine("logs", "log.log"),
outputTemplate: "{Timestamp:HH:mm:ss,fff} {Level:u3} {ThreadId,-2} {Message:lj}{NewLine}{Exception}",
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true);
Serilog.Log.Logger = logConf.CreateLogger();
Log.Info("Logger will also write to file");
}
var starter = new StartUp(opt);
starter.Start();
})
.WithNotParsed((ex) =>
{
if (ex.All(err =>
new ErrorType[]
{
ErrorType.HelpRequestedError,
ErrorType.HelpVerbRequestedError,
ErrorType.VersionRequestedError
}.Contains(err.Tag))
)
return;
foreach (var error in ex)
Log.Error($"Failed to parse: {error.Tag}");
});
#if !DEBUG
}
catch (Exception ex)
{
Log.Fatal(ex);
}
#endif
}
private static LoggerConfiguration GetDefaultLoggerConfiguration()
{
return new LoggerConfiguration()
.Enrich.WithThreadId()
.MinimumLevel.Information()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss,fff} {Level:u3} {ThreadId,-2} {Message:lj}{NewLine}{Exception}");
}
}
}