当前位置: 首页>>代码示例>>C#>>正文


C# Exception.GetErrorMessage方法代码示例

本文整理汇总了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);
        }
开发者ID:Fermium-co,项目名称:TfsWitAdminTools,代码行数:20,代码来源:LogFileTools.cs

示例2: ShowException

 public static MessageBoxResult ShowException(Exception exception)
 {
     return MessageBox.Show(exception.GetErrorMessage(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
 }
开发者ID:Fermium-co,项目名称:TfsWitAdminTools,代码行数:4,代码来源:MessageBoxTools.cs

示例3: Error

 public void Error(Exception exception)
 {
     Error(exception, exception.GetErrorMessage());
 }
开发者ID:domenkogler,项目名称:Framework-old,代码行数:4,代码来源:Logger.cs

示例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);
            }
        }
开发者ID:MGramolini,项目名称:vodca,代码行数:96,代码来源:VLogError.Stack.cs


注:本文中的System.Exception.GetErrorMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。