Vorrei registrare le eccezioni non gestite, ma sto vedendo informazioni contrastanti su se e come ciò sia possibile.Registrazione delle eccezioni Xamarin non gestite (Android non acquisite)
Capisco che Xamarin solleva un evento AndroidEnvironment.UnhandledExceptionRaiser
o AppDomain.CurrentDomain.UnhandledException
e che posso iscrivermi a questo evento, ma ho l'impressione che Android stia uccidendo il mio processo e che non abbia accesso ad Android.Utils.Log o il file system.
Se si dà un'occhiata a Xamarin AdvancedAppLifecycleDemos/HandlingCrashes/App.cs c'è un argomento convincente che non è possibile registrare questa eccezione.
/// <summary>
/// When app-wide unhandled exceptions are hit, this will handle them. Be aware however, that typically
/// android will be destroying the process, so there's not a lot you can do on the android side of things,
/// but your xamarin code should still be able to work. so if you have a custom err logging manager or
/// something, you can call that here. You _won't_ be able to call Android.Util.Log, because Dalvik
/// will destroy the java side of the process.
/// </summary>
protected void HandleUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
// log won't be available, because dalvik is destroying the process
//Log.Debug (logTag, "MyHandler caught : " + e.Message);
// instead, your err handling code shoudl be run:
Console.WriteLine("========= MyHandler caught : " + e.Message);
}
Quindi, come può essere registrata un'eccezione non gestita?
Hi Adam! Hai visto questo thread? https://forums.xamarin.com/discussion/13784/catching-global-exceptions-in-android notano il fatto che 'Console.Writeline' non sembra funzionare ma il' Android.Util.Log.Debug' è. –
Non ho visto quel thread in particolare, ma ho ancora l'impressione che Android.Util.Log possa o meno funzionare poiché Android è attivamente nel processo di eliminazione del processo (come indicato in https: // github .com/Xamarin/MonoDroid-campioni/albero/padrone/AdvancedAppLifecycleDemos/HandlingCrashes). – Adam
Hai considerato Xamarin.Insights? Potrebbe intercettare le eccezioni non gestite e gestite dopo l'inizializzazione su mainactivity/appdelegate ma sembra esserci un compromesso tra le informazioni che rallentano le applicazioni multithread sulla piattaforma Android. –