本文整理汇总了C#中System.Exception.GetErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.GetErrorMessage方法的具体用法?C# Exception.GetErrorMessage怎么用?C# Exception.GetErrorMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.GetErrorMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogException
public static void LogException(Exception exception)
{
var innerExceptionItem = exception.InnerException;
var sb = new StringBuilder();
sb.AppendLine(string.Format("------------#Exception - {0} -----------------------------------------------------------------------------------",
DateTime.Now.ToString()));
sb.AppendLine(exception.GetErrorMessage()).AppendLine();
var innerExceptionCount = 0;
while (innerExceptionItem != null)
{
innerExceptionCount++;
sb
.AppendLine(string.Format("Inner Exception #{0}: \n{1}\n\n Stack : \n{2}\n",
innerExceptionCount, innerExceptionItem.Message, innerExceptionItem.StackTrace.ToString()));
innerExceptionItem = innerExceptionItem.InnerException;
}
sb.AppendLine();
File.AppendAllText("LogFile.txt", sb.ToString(), Encoding.UTF8);
}
示例2: ShowException
public static MessageBoxResult ShowException(Exception exception)
{
return MessageBox.Show(exception.GetErrorMessage(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
示例3: Error
public void Error(Exception exception)
{
Error(exception, exception.GetErrorMessage());
}
示例4: SetExceptionAddtionalInformation
public void SetExceptionAddtionalInformation(Exception exception)
{
var exceptionStack = new Stack<Exception>();
// create exception stack
for (Exception e = exception; e != null; e = e.InnerException)
{
exceptionStack.Push(e);
}
if (this.ErrorStackData == null)
{
this.ErrorStackData = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
}
try
{
this.ErrorStackData["ExceptionSource"] = exception.GetErrorSource();
this.ErrorStackData["ExceptionMessage"] = exception.GetErrorMessage();
this.ErrorStackData["ExceptionTypeName"] = exception.GetErrorTypeName();
this.ErrorStackData["ExceptionHelpLink"] = exception.HelpLink;
if (exceptionStack.Count != 0)
{
// render exception type and message
Exception ex = exceptionStack.Pop();
// Load stack trace
var stackTrace = new StackTrace(ex, true);
for (int frame = 0; frame < stackTrace.FrameCount; frame++)
{
StackFrame stackFrame = stackTrace.GetFrame(frame);
MethodBase method = stackFrame.GetMethod();
Type declaringType = method.DeclaringType;
if (declaringType != typeof(Ensure) && stackFrame.GetFileLineNumber() > 0)
{
this.ErrorStackData["HostingEnvironmentApplicationPhysicalPath"] = HostingEnvironment.ApplicationPhysicalPath;
this.ErrorStackData["HttpRuntimeAppDomainAppId"] = HttpRuntime.AppDomainAppId;
this.ErrorStackData["EnvironmentMachineName"] = Environment.MachineName;
this.ErrorStackData["CurrentCultureDisplayName"] = Thread.CurrentThread.CurrentCulture.DisplayName;
if (declaringType != null)
{
this.ErrorStackData["TypeGUID"] = declaringType.GUID.ToShortId();
this.ErrorStackData["TypeFullName"] = declaringType.FullName;
this.ErrorStackData["TypeAssemblyQualifiedName"] = declaringType.AssemblyQualifiedName;
this.ErrorStackData["TypeNamespace"] = declaringType.Namespace;
this.ErrorStackData["AssemblyName"] = Path.GetFileName(declaringType.Assembly.Location);
}
var csfilename = stackFrame.GetFileName();
if (!string.IsNullOrWhiteSpace(csfilename))
{
this.ErrorStackData["StackFrameFileName"] = stackFrame.GetFileName();
this.ErrorStackData["StackFrameFileNameVirtualPath"] = csfilename.Replace(HostingEnvironment.ApplicationPhysicalPath, "/").Replace('\\', '/');
}
this.ErrorStackData["StackFrameFileLineNumber"] = stackFrame.GetFileLineNumber().ToString(CultureInfo.InvariantCulture);
this.ErrorStackData["StackFrameShortFileName"] = Path.GetFileName(stackFrame.GetFileName());
var trace = new StringBuilder(64);
if (declaringType != null)
{
trace.Append(declaringType.Namespace).Append('.').Append(declaringType.Name).Append('.').Append(method.Name);
}
this.ErrorStackData["MethodBaseName"] = trace.ToString();
trace.Append('(');
// get parameter information
ParameterInfo[] parameters = method.GetParameters();
for (int paramIndex = 0; paramIndex < parameters.Length; paramIndex++)
{
trace.Append(((paramIndex != 0) ? "," : string.Empty) + parameters[paramIndex].ParameterType.Name + " " + parameters[paramIndex].Name);
}
trace.Append(')');
this.ErrorStackData["MethodBaseFullName"] = trace.ToString();
break;
}
}
}
}
catch (Exception ex)
{
VLog.Logger.InfoException("GetExceptionAddtionalInformation", ex);
}
}