- On Linux, a desktop computer with a wireless mouse, keyboard, headset or game controller was described as a laptop, with the advice to use a small always-on computer instead, because the battery inside the mouse was counted. Only the computer's own battery counts now. - The mail card now leads with what big mailboxes care about most: when your address's reverse name looks like a home line, or there is none, that comes first. A blocklist that names your provider's whole network is still shown below it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using Avalonia.Threading;
|
|
|
|
using MeWeb.Shared;
|
|
|
|
namespace MeWeb.App.Services;
|
|
|
|
public static class ErrorLog
|
|
{
|
|
const long MaxBytes = 256 * 1024;
|
|
static string FilePath => Path.Combine(AppServices.Folder, "errors.log");
|
|
static readonly Lock Gate = new();
|
|
|
|
public static void Watch()
|
|
{
|
|
Dispatcher.UIThread.UnhandledException += OnDispatcher;
|
|
TaskScheduler.UnobservedTaskException += OnUnobserved;
|
|
AppDomain.CurrentDomain.UnhandledException += OnDomain;
|
|
}
|
|
|
|
public static void Write(Exception error)
|
|
{
|
|
if (error is null) return;
|
|
lock (Gate)
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
|
|
if (File.Exists(FilePath) && new FileInfo(FilePath).Length > MaxBytes) File.Delete(FilePath);
|
|
File.AppendAllText(FilePath, $"{DateTimeOffset.UtcNow:O} me-web? {BuildInfo.Version}{Environment.NewLine}{error}{Environment.NewLine}{Environment.NewLine}");
|
|
}
|
|
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
static void OnDispatcher(object sender, DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
Write(e.Exception);
|
|
e.Handled = true;
|
|
}
|
|
|
|
static void OnUnobserved(object sender, UnobservedTaskExceptionEventArgs e)
|
|
{
|
|
Write(e.Exception);
|
|
e.SetObserved();
|
|
}
|
|
|
|
static void OnDomain(object sender, UnhandledExceptionEventArgs e) => Write(e.ExceptionObject as Exception);
|
|
}
|