示例#1
0
        /// <summary>
        // If there is an unhandled exception, the exception information is diplayed
        // on screen the next time the app is started (only in debug configuration)
        /// </summary>
        //[Conditional("DEBUG")]
        private async void DisplayCrashReport()
        {
            const string errorFilename = "Fatal.log";
            var          libraryPath   = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var          errorFilePath = Path.Combine(libraryPath, errorFilename);

            if (!File.Exists(errorFilePath))
            {
                Toast.MakeText(this, "Hooray! No error since last launch!", ToastLength.Long).Show();
                return;
            }

            var errorText = File.ReadAllText(errorFilePath);
            await ErrorReporter.ReportErrorAsync(errorText);

            new AlertDialog.Builder(this)
            .SetPositiveButton("Clear", (sender, args) =>
            {
                File.Delete(errorFilePath);
            })
            .SetNegativeButton("Close", (sender, args) =>
            {
                // User pressed Close.
            })
            .SetMessage(errorText)
            .SetTitle("Crash Report")
            .Show();
        }