Xamarin Logging Unhandled (Android Excluded Exceptions) Exceptions

I would like to log unhandled exceptions, but I see conflicting information about if and how this is possible.

I understand that Xamarin raises an AndroidEnvironment.UnhandledExceptionRaiser or AppDomain.CurrentDomain.UnhandledException event and that I can subscribe to this event, but I get the impression that Android is killing my process and I don’t have access to Android.Utils.Log or the file system .

If you look at Xamarin AdvancedAppLifecycleDemos / HandlingCrashes / App.cs , there is a convincing argument that you cannot register this exception.

  /// <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 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); } 

So how can an unhandled exception be logged?

+8
android xamarin xamarin.android
source share
2 answers

Xamarin Insights, HockeyApp, or other crash loggers store crash data anyway before the application completes the process. They send data to the server after the application is restarted (they cannot send it immediately after the process is killed). So it is quite possible. Although I'm not sure that they store the crash data in the device store (most likely) or in the local SQLite database.

HockeyApp uses this code to detect unhandled exceptions. This may give you some ideas:

 AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) => { TraceWriter.WriteTrace(args.Exception); args.Handled = true; }; AppDomain.CurrentDomain.UnhandledException += (sender, args) => TraceWriter.WriteTrace(args.ExceptionObject); // Wire up the unobserved task exception handler TaskScheduler.UnobservedTaskException += (sender, args) => TraceWriter.WriteTrace(args.Exception); 

I would suggest trying and writing a text file in local storage in any of these methods

+7
source share

Xamarin Insights is what you need: https://xamarin.com/insights

With Xamarin Insights, you can see a complete overview of any crashes and determine what types of problems and warnings are occurring in your application.

When the final version of Xamarin Studio 5.10 is released, Insights will also be integrated ( more ).

0
source share

All Articles