63 lines
2.0 KiB
C#
Raw Normal View History

2023-11-12 09:52:02 -05:00
using System.Linq;
using Avalonia;
2023-05-11 23:11:39 -04:00
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
2023-09-05 20:09:11 -04:00
using ReactiveUI;
using Serilog;
2023-05-11 23:11:39 -04:00
using SPTInstaller.ViewModels;
using SPTInstaller.Views;
2023-09-05 20:09:11 -04:00
using System.Reactive;
2023-05-11 23:11:39 -04:00
namespace SPTInstaller;
public partial class App : Application
2023-05-11 23:11:39 -04:00
{
2024-02-06 18:59:39 -05:00
private readonly string _logPath = Path.Join(Environment.CurrentDirectory, "spt-aki-installer_.log");
2024-05-01 10:31:55 -04:00
public override void Initialize()
2023-05-11 23:11:39 -04:00
{
AvaloniaXamlLoader.Load(this);
2024-02-06 18:59:39 -05:00
2023-09-05 20:23:28 -04:00
Log.Logger = new LoggerConfiguration()
2024-02-06 18:59:39 -05:00
.MinimumLevel.Information()
2023-09-05 20:23:28 -04:00
.WriteTo
2024-02-06 18:59:39 -05:00
.File(path: _logPath,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information,
2023-09-05 20:23:28 -04:00
rollingInterval: RollingInterval.Day)
.CreateLogger();
2024-05-01 10:31:55 -04:00
2023-09-05 20:09:11 -04:00
RxApp.DefaultExceptionHandler = Observer.Create<Exception>((exception) =>
{
Log.Error(exception, "An application exception occurred");
});
}
2024-05-01 10:31:55 -04:00
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
2023-05-11 23:11:39 -04:00
{
2024-02-06 18:59:39 -05:00
var debug = desktop.Args != null && desktop.Args.Any(x => x.ToLower() == "debug");
if (debug)
2023-11-12 09:52:02 -05:00
{
2024-02-06 18:59:39 -05:00
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo
.File(path: _logPath,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug,
rollingInterval: RollingInterval.Day)
.CreateLogger();
2023-11-12 09:52:02 -05:00
System.Diagnostics.Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener());
2024-02-06 18:59:39 -05:00
2023-11-12 09:52:02 -05:00
Log.Debug("TraceListener is registered");
}
desktop.MainWindow = new MainWindow
2023-05-11 23:11:39 -04:00
{
2024-02-06 18:59:39 -05:00
DataContext = new MainWindowViewModel(debug),
};
2023-05-11 23:11:39 -04:00
}
2024-05-01 10:31:55 -04:00
base.OnFrameworkInitializationCompleted();
2023-05-11 23:11:39 -04:00
}
}