63 lines
1.7 KiB
C#
63 lines
1.7 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");
|
|
var text = DateTime.Now.ToString("HH:mm:ss.fff ") + line + Environment.NewLine;
|
|
using var fs = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read);
|
|
var bytes = System.Text.Encoding.UTF8.GetBytes(text);
|
|
fs.Write(bytes, 0, bytes.Length);
|
|
fs.Flush(flushToDisk: true);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|