本文整理汇总了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;
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例8: Error
public void Error(Exception exception)
{
mainViewModel.LogError(exception.Format(), DateTime.Now);
}
示例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;
}
示例10: Error
public void Error(Exception exception)
{
Application.Current.Sync()
.Execute(() => DialogService.DialogService.ShowMessage("Error", exception.Format(), MessageBoxButton.OK, MessageBoxImage.Error));
}
示例11: FormatMessage
static string FormatMessage(Exception e, string message) {
if (string.IsNullOrWhiteSpace(message))
return e.Format();
return message + ": " + e.Format();
}
示例12: Failed
public void Failed(Exception exception)
{
HasErrors = true;
Append("Error before start {0}, message: {1}", operationName, exception.Format());
}
示例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));
}
示例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;
}