【问题标题】:Xamarin.Android: Save Crash-Reports (Save StackTrace)Xamarin.Android:保存崩溃报告(保存 StackTrace)
【发布时间】:2018-09-26 05:45:23
【问题描述】:

当我的 Xamarin.Android 应用程序崩溃时,我正在尝试保存我的错误消息和 StackTrace。

在 Xamarin.iOS 中,我可以简单地将 Main-Method 包装在 Try-Catch-Block 中,如下面的屏幕截图所示:

由于 Xamarin.Android 中没有 Main-Method(只有我的 MainLauncher Activity),我问自己一个问题,是否有类似的简单方法来记录异常。

【问题讨论】:

    标签: exception logging xamarin.android stack-trace crash-reports


    【解决方案1】:

    我找到了记录所有未处理异常的解决方案:

    在我的 MainLauncher 活动中:

        protected override void OnCreate(Bundle bundle) 
        {
            base.OnCreate(bundle);
            AndroidEnvironment.UnhandledExceptionRaiser += HandleAndroidException;
    

    private void HandleAndroidException(object sender, RaiseThrowableEventArgs e)
            {
                e.Handled = true;
                Logger = new LogUtils();
                Logger.Log("ERROR: Unhandled Exception");
                Logger.Log("MESSAGE: " + e.Exception.Message);
                Logger.Log("STACKTRACE: " + e.Exception.StackTrace);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多