The MAUI platform have failed to provide an unified way of tracking unhandled exceptions.
The normal way would be to hook into AppDomain.CurrentDomain.UnhandledException
, but extra logic needed for iOS and Android:
Exceptions on iOS flows through AppDomain.CurrentDomain.UnhandledException, but one must set UnwindNativeCode:
ObjCRuntime.Runtime.MarshalManagedException += (_, args) => { args.ExceptionMode = ObjCRuntime.MarshalManagedExceptionMode.UnwindNativeCode; };
Exceptions on Android only flows through Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser
:
Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) => { // Log unhandled args.Exception };
NLog.Targets.MauiLog includes unified method to setup UnhandledExceptionEventHandler
:
NLog.LogManager.Setup().RegisterMauiLog((sender, ex) => { NLog.LogManager.GetLogger("Application").Fatal(ex, "Unhandled Exception"); });
One can also consider monitoring unobserved task exceptions:
TaskScheduler.UnobservedTaskException += (sender, args) => { NLog.LogManager.GetLogger("Application").Error(args.Exception, "Unobserved Task Exception"); };
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4