Repository navigation
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
81 lines (76 loc) · 2.25 KB
/
Copy pathApp.xaml.cs
File metadata and controls
81 lines (76 loc) · 2.25 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
using System.Windows;
using Serilog;
namespace XISOSharpTester;
/// <summary>
/// Application entry point for the XISOSharp Tester WPF application.
/// Configures Serilog logging (file/debug/console + Warning+ bug-report API),
/// writes the log to a rolling file in local app data, and logs startup
/// and shutdown events.
/// </summary>
public partial class App
{
/// <summary>
/// Configures Serilog logging before the application window opens.
/// </summary>
protected override void OnStartup(StartupEventArgs e)
{
try
{
AppLogging.Configure("XISOSharpTester");
// Launch ping for usage stats (fire-and-forget; test hosts and
// XISO_DISABLE_STATS=1 are honored inside ApplicationStats).
ApplicationStats.RecordLaunch("xisosharp-tester");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"AppLogging.Configure failed: {ex.Message}");
}
try
{
base.OnStartup(e);
Log.Information("XISOSharpTester started");
}
catch (Exception ex)
{
Log.Error(ex, "Application startup failed");
throw;
}
}
/// <summary>
/// Logs the shutdown event and flushes the Serilog log before
/// the application exits.
/// </summary>
protected override void OnExit(ExitEventArgs e)
{
try
{
Log.Information("XISOSharpTester exiting");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"OnExit logging failed: {ex.Message}");
}
finally
{
// Deliver pending bug-report sends before the process exits.
try
{
BugReporter.Flush(TimeSpan.FromSeconds(2));
ApplicationStats.Flush(TimeSpan.FromSeconds(2));
}
catch
{
// Reporting must never fail shutdown.
}
AppLogging.CloseAndFlush();
try
{
base.OnExit(e);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"OnExit failed: {ex.Message}");
}
}
}
}