Layers/shell/windows/LayersShell/App.xaml.cs

59 lines
1.5 KiB
C#

using System;
using System.IO;
using Microsoft.UI.Xaml;
namespace LayersShell;
public partial class App : Application
{
private MainWindow? _window;
public App()
{
Log("App ctor enter");
try
{
AppDomain.CurrentDomain.FirstChanceException += (_, e) =>
Log($"FirstChance: {e.Exception.GetType().Name}: {e.Exception.Message}");
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
Log($"UnhandledException: {e.ExceptionObject}");
UnhandledException += (_, e) =>
Log($"XAML UnhandledException: {e.Exception}");
InitializeComponent();
Log("App ctor ok");
}
catch (Exception ex)
{
Log($"App ctor FAILED: {ex}");
throw;
}
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Log("OnLaunched enter");
try
{
_window = new MainWindow();
Log("MainWindow constructed");
_window.Activate();
Log("MainWindow activated");
}
catch (Exception ex)
{
Log($"OnLaunched FAILED: {ex}");
throw;
}
}
internal static void Log(string line)
{
try
{
var path = Path.Combine(Path.GetTempPath(), "layers-shell.log");
File.AppendAllText(path, DateTime.Now.ToString("HH:mm:ss.fff ") + line + Environment.NewLine);
}
catch { }
}
}