Scopo: Il nostro scopo qui per afferrare i dati dello stack trace di un'eccezione che ci aiutano a identificare ciò che provoca esattamente la questione se in Release Mode
o Debug Mode
. Saremo in grado di comprendere il problema e il motivo che lo causa. Conserveremo questi dati in un file text
che verrà archiviato nella memoria del dispositivo.
Soluzione: In alternativa, è possibile creare il proprio grabber intuizione che vi darà voi app intuizione e indizio se qualcosa è andato storto durante il test l'applicazione. Sarà tuo, puoi modificare come vuoi. tuffiamoci a try{}
e catch{}
a livello globale.
Creare un file Helper Class
che abbia un metodo per generare un file di testo per dati di eccezione.
public static class ExceptionFileWriter
{
#region Property File Path
static string FilePath
{
get
{
string path = string.Empty;
var _fileName = "Fatal.txt";
#if __IOS__
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // Documents folder C:\ddddd
string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder C:\dddd\...\library
path = Path.Combine(libraryPath, _fileName); //c:\ddddd\...\library\NBCCSeva.db3
#else
#if __ANDROID__
string dir = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), "Exception");
if (Directory.Exists(dir))
return Path.Combine(dir, _fileName);
path= Path.Combine(Directory.CreateDirectory(dir).FullName, _fileName);
#endif
#endif
return path;
}
}
#endregion
#region ToLog Exception
public static void ToLogUnhandledException(this Exception exception)
{
try
{
var errorMessage = String.Format("Time: {0}\r\nError: Unhandled Exception\r\n{1}\n\n", DateTime.Now, string.IsNullOrEmpty(exception.StackTrace) ? exception.ToString() : exception.StackTrace);
File.WriteAllText(FilePath, errorMessage);
}
catch (Exception ex)
{
// just suppress any error logging exceptions
}
}
#endregion
}
tempo per implementare il codice: Iscriviti seguenti eventi all'interno del file della tua applicazione Application
o Splash Activity
. Sto usando l'applicazione in questo caso.
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
[Application]
public class ExceptionHandlingApp : Application
{
#region Constructor
public ExceptionHandlingApp(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
#endregion
#region OnCreate
public override void OnCreate()
{
base.OnCreate();
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
}
#endregion
#region Task Schedular Exception
private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
{
var newExc = new Exception("TaskSchedulerOnUnobservedTaskException", unobservedTaskExceptionEventArgs.Exception);
newExc.ToLogUnhandledException();
}
#endregion
#region Current Domain Exception
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
var newExc = new Exception("CurrentDomainOnUnhandledException", unhandledExceptionEventArgs.ExceptionObject as Exception);
newExc.ToLogUnhandledException();
}
#endregion
}
Nota: è possibile trovare delle eccezioni file di record nella Storage Device | File Manager> Cartella eccezione> fatal.txt
Evviva !!
Result Video
Full Article
Naturalmente utilizzabili Grazie per l'aggiunta, ma credo che il suo insieme Business Edition. Per favore correggimi se sbaglio. – RIYAZ
Almeno per oggi è gratuito e illimitato per tutti i clienti Xamarin. Quando Xamarin.Insights è stato annunciato c'è stata questa frase sui prezzi: * I prezzi saranno annunciati alla fine dell'anteprima, ma un piano generoso sarà incluso per gli abbonati Xamarin senza costi aggiuntivi. * Https: //blog.xamarin. com/monitoring-your-apps-with-xamarin-insights/ – Wosi
Beh, è carino :) Grazie per aver condiviso @Wosi. – RIYAZ