當前位置: 首頁>>代碼示例>>C#>>正文


C# Exception.Format方法代碼示例

本文整理匯總了C#中System.Exception.Format方法的典型用法代碼示例。如果您正苦於以下問題:C# Exception.Format方法的具體用法?C# Exception.Format怎麽用?C# Exception.Format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Exception的用法示例。


在下文中一共展示了Exception.Format方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Format

 private static LogInfo Format(string msg, Exception ex = null)
 {
     var f = new StackFrame(6, true);
     var method = f.GetMethod();
     var fileInfo = string.Format("{0}[{1}]", f.GetFileName(), f.GetFileLineNumber());
     if (ex != null)
     {
         method = ex.TargetSite;
     }
     var result = new LogInfo
     {
         Method = string.Format("{0} {1}",
             method.DeclaringType,
             method.Name),
         Message = msg,
         File = string.Empty,
         Detail = string.Empty
     };
     result.File = fileInfo;
     if (ex != null)
     {
         result.Detail = ex.Format();
     }
     return result;
 }
開發者ID:shoy160,項目名稱:Shoy.Common,代碼行數:25,代碼來源:Log4NetLog.cs

示例2: HandleEx

        static void HandleEx(Exception ex) {
            MainLog.Logger.Fatal(ex.Format(), LogLevel.Fatal);
            MessageBox.Show(
                "Info: " + ex.Message + "\n\n"
                +
                "The application will exit now. We've been notified about the problem. Sorry for the inconvenience\n\nIf the problem persists, please contact Support: http://community.withsix.com",
                "Unrecoverable error occurred");

            Environment.Exit(1);
        }
開發者ID:SIXNetworks,項目名稱:withSIX.Desktop,代碼行數:10,代碼來源:ExDialog.cs

示例3: WriteError

        /// <summary>
        /// Logs exception to error log
        /// </summary>
        /// <param name="exception"></param>
        static public void WriteError(Exception exception)
        {
            if (exception == null)
                return;

            Trace.TraceError(
                Environment.NewLine +
                String.Format("Date: {0:d} {0:T}", DateTime.Now) +
                Environment.NewLine +
                exception.Format());
        }
開發者ID:peschuster,項目名稱:propresenter-remote,代碼行數:15,代碼來源:Program.cs

示例4: Error

		public void Error(Exception exception)
		{
			var lines =
				new[]
					{
						"========================================================",
						string.Format("WriteLog error at {0}", DateTime.Now.FullTime()),
						exception.Format()
					};

			File.AppendAllLines(Path.Combine(folder, "Log.Exceptions.txt"), lines);
		}
開發者ID:matteomigliore,項目名稱:HSDK,代碼行數:12,代碼來源:LoggerExceptions.cs

示例5: Error

        private static void Error(Exception ex, int exitCode) {
            var formatted = ex.Format();
            Console.Error.WriteLine(
#if DEBUG
                formatted
#else
                ex.Message
#endif
            );
            MainLog.Logger.Error(formatted);
            Environment.Exit(exitCode);
        }
開發者ID:SIXNetworks,項目名稱:withSIX.Desktop,代碼行數:12,代碼來源:Program.cs

示例6: FatalException

        public void FatalException(Exception e, string message = null) {
            if (message != null)
                e = ExceptionExtensions.HandledException(e, message);

            MainLog.Logger.FormattedErrorException(e, message);
            System.Console.WriteLine(e.Format());

            if (!Common.Flags.Merged)
                return;

            ExceptionReporting.Report(e);
        }
開發者ID:MaHuJa,項目名稱:withSIX.Desktop,代碼行數:12,代碼來源:Program.cs

示例7: OnError

 protected override void OnError(TransferSpec spec, Exception e) {
     if (e is OperationCanceledException) {
         this.Logger()
             .Warn(
                 $"Cancelled download of {spec.Uri} to {spec.LocalFile}, try {spec.Progress.Tries} ({e.Message})");
         return;
     }
     var msg =
         $"Failed download of {spec.Uri} to {spec.LocalFile}, try {spec.Progress.Tries} ({e.Message})\nOutput: {spec.Progress.Output}\n\nError report: {e.Format(1)}";
     if (spec.Progress.Tries > 1)
         this.Logger().Warn(msg);
     else
         this.Logger().Error(msg);
 }
開發者ID:SIXNetworks,項目名稱:withSIX.Desktop,代碼行數:14,代碼來源:LoggingFileDownloaderDecorator.cs

示例8: Error

		public void Error(Exception exception)
		{
			mainViewModel.LogError(exception.Format(), DateTime.Now);
		}
開發者ID:matteomigliore,項目名稱:HSDK,代碼行數:4,代碼來源:ViewLogger.cs

示例9: ExceptionDialog

 public async Task<bool> ExceptionDialog(Exception e, string message, string title = null, object window = null) {
     await _api.ShowMessageBox(title, message + "\n" + e.Format(), null, "error").ConfigureAwait(false);
     return true;
 }
開發者ID:SIXNetworks,項目名稱:withSIX.Desktop,代碼行數:4,代碼來源:NodeDialogManager.cs

示例10: Error

		public void Error(Exception exception)
		{
			Application.Current.Sync()
				.Execute(() => DialogService.DialogService.ShowMessage("Error", exception.Format(), MessageBoxButton.OK, MessageBoxImage.Error));
		}
開發者ID:matteomigliore,項目名稱:HSDK,代碼行數:5,代碼來源:DialogLogger.cs

示例11: FormatMessage

 static string FormatMessage(Exception e, string message) {
     if (string.IsNullOrWhiteSpace(message))
         return e.Format();
     return message + ": " + e.Format();
 }
開發者ID:MaHuJa,項目名稱:withSIX.Desktop,代碼行數:5,代碼來源:Logger.cs

示例12: Failed

		public void Failed(Exception exception)
		{
			HasErrors = true;

			Append("Error before start {0}, message: {1}", operationName, exception.Format());
		}
開發者ID:matteomigliore,項目名稱:HSDK,代碼行數:6,代碼來源:DatabaseLogger.cs

示例13: OnError

 protected override void OnError(TransferSpec spec, Exception e) {
     this.Logger()
         .Error("Failed download of {0} to {1}, try {2} ({3})\nOutput: {4}\n\nError report: {5}", spec.Uri,
             spec.LocalFile, spec.Progress.Tries, e.Message, spec.Progress.Output, e.Format(1));
 }
開發者ID:MaHuJa,項目名稱:withSIX.Desktop,代碼行數:5,代碼來源:LoggingFileDownloaderDecorator.cs

示例14: ShowExceptionDialog

        static bool ShowExceptionDialog(string message, string title, Exception e, object window = null) {
            message = new XmlSanitizer().SanitizeXmlString(message);

            var ev = new ExceptionDialogViewModel(e.Format()) {
                Message = message,
                Title = title,
                Exception = e
            };

            var w = new ExceptionDialogView {DataContext = ev};
            if (window == null)
                DialogHelper.SetMainWindowOwner(w);
            else
                w.Owner = (Window) window;
            w.ShowDialog();

            if (ev.Throw)
                throw new ExceptionDialogThrownException("Redirected exception", e);

            return ev.Cancel;
        }
開發者ID:MaHuJa,項目名稱:withSIX.Desktop,代碼行數:21,代碼來源:WpfDialogManager.cs


注:本文中的System.Exception.Format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。