Ejemplo n.º 1
0
        public static String GetExceptionDetails(Exception e)
        {
            String details = e.Message;

            StackTrace stack = new StackTrace(e);

            if (stack.FrameCount > 0)
            {
                StackFrame frame = stack.GetFrame(stack.FrameCount - 1);
                if (frame != null)
                {
                    MethodBase method = frame.GetMethod();
                    if (method != null)
                    {
                        string methodName = method.Name;
                        if (Utils.Empty(methodName) == false)
                        {
                            string className = method.ReflectedType != null ? method.ReflectedType.FullName : null;
                            if (Utils.Empty(className) == false)
                            {
                                methodName = className + "." + methodName;
                            }

                            if (Utils.Empty(details) == false)
                            {
                                details += " ";
                            }

                            string fileName   = frame.GetFileName();
                            int    fileLine   = frame.GetFileLineNumber();
                            int    fileColumn = frame.GetFileColumnNumber();

                            string fileInfo = "";
                            if ((Utils.Empty(fileName) == false) || (fileLine != 0) || (fileColumn != 0))
                            {
                                fileInfo = " at file:line:column " + String.Format("{0}:{1}:{2}", Utils.Empty(fileName) ? "?" : fileName, fileLine != 0 ? Convert.ToString(fileLine) : "?", fileColumn != 0 ? Convert.ToString(fileColumn) : "?");
                            }

                            details += "(" + methodName + fileInfo + ")";
                        }
                    }
                }
            }

            return(details);
        }