/// <summary> /// Easy to use Exception logger that shows the user a custom error message /// </summary> /// <param name="exception">Exception that occurs</param> /// <param name="dialogTitle">MessageDialog's title</param> /// <param name="dialogMessage">MessageDialog's message</param> /// <returns>Task</returns> public static async Task LogExceptionWithUserMessage(this Exception exception, string dialogMessage, string dialogTitle) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } Trace.TraceError($"LogExceptionWithUserMessage {exception.Message}"); if (string.IsNullOrEmpty(dialogTitle)) { throw new ArgumentNullException(nameof(dialogTitle)); } if (string.IsNullOrEmpty(dialogMessage)) { throw new ArgumentNullException(nameof(dialogMessage)); } if (string.IsNullOrEmpty(dialogMessage)) { dialogMessage = "Sorry, there has been an unexpected error. If you'd like to send a technical summary to the app development team, click Yes."; } var exceptionMessage = CreateErrorMessage(exception); // Manages and saves local log files await LogFileWriteAsync(exceptionMessage); var md = new MessageDialog(dialogMessage, dialogTitle); md.Commands.Add(new UICommand("yes (summary)")); md.Commands.Add(new UICommand("yes (full)")); md.Commands.Add(new UICommand("no")); var result = await md.ShowAsync(); switch (result.Label) { case "yes (summary)": await FeedbackHelpers.Current.EmailErrorMessageAsync(exceptionMessage); break; case "yes (full)": { var text = await DiagnosticsHelper.DumpAsync(exception); await FeedbackHelpers.Current.EmailErrorMessageAsync(exceptionMessage + "\r\n\n" + text); break; } } }
/// <summary> /// Easy to use Exception logger that shows the user an error message with the following MessageDialog /// Title: Unexpected Error /// Message: Sorry, there has been an unexpected error. If you'd like to send a technical summary to the app development team, click Yes. /// </summary> /// <param name="exception"></param> /// <returns></returns> public static async Task LogExceptionWithUserMessage(this Exception exception) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } Trace.TraceError(exception.Message); //Crashes.TrackError(currentException); var exceptionMessage = CreateErrorMessage(exception); var logFile = await LogFileWriteAsync(exceptionMessage); var md = new MessageDialog( "Sorry, something went wrong. Will you please send us the crash report? Just click an option and we'll automatically draft the email:", "Unexpected Error"); md.Commands.Add(new UICommand("yes (recommended)", async command => { var dumpDetails = await DiagnosticsHelper.DumpAsync(exception); var subject = "MVP Companion Error Report"; var body = exceptionMessage + "\r\n\n" + dumpDetails; await FeedbackHelpers.Current.EmailErrorWithAttachmentAsync(subject, body, logFile); })); md.Commands.Add(new UICommand("yes (device info)", async command => { var dumpDetailsWithDeviceInfo = await DiagnosticsHelper.DumpAsync(exception, true); var subject = "MVP Companion Error Report"; var body = exceptionMessage + "\r\n\n" + dumpDetailsWithDeviceInfo; await FeedbackHelpers.Current.EmailErrorWithAttachmentAsync(subject, body, logFile); })); md.Commands.Add(new UICommand("no")); await md.ShowAsync(); }