private static RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
    {
      var lines = new List<RaygunErrorStackTraceLineMessage>();

      string[] delim = { "\r\n" };
      string stackTrace = exception.StackTrace ?? exception.Data["Message"] as string;
      exception.Data.Remove("Message");
      if (stackTrace != null)
      {
        var frames = stackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);

        foreach (string line in frames)
        {
          // Trim the stack trace line
          string stackTraceLine = line.Trim();
          if (stackTraceLine.StartsWith("at "))
          {
            stackTraceLine = stackTraceLine.Substring(3);
          }

          int lineNumber = 0;
          string className = stackTraceLine;
          string methodName = null;
          string fileName = null;

          int index = stackTraceLine.LastIndexOf(":line ", StringComparison.Ordinal);
          if (index > 0)
          {
            string number = stackTraceLine.Substring(index + 6);
            Int32.TryParse(number, out lineNumber);
            stackTraceLine = stackTraceLine.Substring(0, index);
          }
          index = stackTraceLine.LastIndexOf(") in ", StringComparison.Ordinal);
          if (index > 0)
          {
            fileName = stackTraceLine.Substring(index + 5);
            stackTraceLine = stackTraceLine.Substring(0, index + 1);
          }
          index = stackTraceLine.IndexOf("(", StringComparison.Ordinal);
          if (index > 0)
          {
            index = stackTraceLine.LastIndexOf(".", index, StringComparison.Ordinal);
            if (index > 0)
            {
              className = stackTraceLine.Substring(0, index);
              methodName = stackTraceLine.Substring(index + 1);
            }
          }

          RaygunErrorStackTraceLineMessage stackTraceLineMessage = new RaygunErrorStackTraceLineMessage();
          stackTraceLineMessage.ClassName = className;
          stackTraceLineMessage.MethodName = methodName;
          stackTraceLineMessage.FileName = fileName;
          stackTraceLineMessage.LineNumber = lineNumber;
          lines.Add(stackTraceLineMessage);
        }
      }

      return lines.ToArray();
    }
    private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
    {
      var lines = new List<RaygunErrorStackTraceLineMessage>();

      try
      {
        RaygunErrorStackTraceLineMessage[] array = ParseStackTrace(exception.StackTrace);
        if (array.Length > 0)
        {
          return array;
        }
      }
      catch { }



      var stackTrace = new StackTrace(exception, true);
      var frames = stackTrace.GetFrames();

      if (frames == null || frames.Length == 0)
      {
        return lines.ToArray();
      }

      foreach (StackFrame frame in frames)
      {
        MethodBase method = frame.GetMethod();

        if (method != null)
        {
          int lineNumber = frame.GetFileLineNumber();

          if (lineNumber == 0)
          {
            lineNumber = frame.GetILOffset();
          }

          var methodName = GenerateMethodName(method);

          string file = frame.GetFileName();

          string className = method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)";

          var line = new RaygunErrorStackTraceLineMessage
          {
            FileName = file,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
          };

          lines.Add(line);
        }
      }

      return lines.ToArray();
    }
Exemple #3
0
        private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

            try
            {
                RaygunErrorStackTraceLineMessage[] array = ParseStackTrace(exception.StackTrace);
                if (array.Length > 0)
                {
                    return(array);
                }
            }
            catch { }



            var stackTrace = new StackTrace(exception, true);
            var frames     = stackTrace.GetFrames();

            if (frames == null || frames.Length == 0)
            {
                return(lines.ToArray());
            }

            foreach (StackFrame frame in frames)
            {
                MethodBase method = frame.GetMethod();

                if (method != null)
                {
                    int lineNumber = frame.GetFileLineNumber();

                    if (lineNumber == 0)
                    {
                        lineNumber = frame.GetILOffset();
                    }

                    var methodName = GenerateMethodName(method);

                    string file = frame.GetFileName();

                    string className = method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)";

                    var line = new RaygunErrorStackTraceLineMessage
                    {
                        FileName   = file,
                        LineNumber = lineNumber,
                        MethodName = methodName,
                        ClassName  = className
                    };

                    lines.Add(line);
                }
            }

            return(lines.ToArray());
        }
        private static RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List<RaygunErrorStackTraceLineMessage>();

              if (exception.StackTrace != null)
              {
            char[] delim = { '\r', '\n' };
            var frames = exception.StackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in frames)
            {
              // Trim the stack trace line
              string stackTraceLine = line.Trim();
              if (stackTraceLine.StartsWith("at "))
              {
            stackTraceLine = stackTraceLine.Substring(3);
              }

              string className = stackTraceLine;
              string methodName = null;

              // Extract the method name and class name if possible:
              int index = stackTraceLine.IndexOf("(");
              if (index > 0)
              {
            index = stackTraceLine.LastIndexOf(".", index);
            if (index > 0)
            {
              className = stackTraceLine.Substring(0, index);
              methodName = stackTraceLine.Substring(index + 1);
            }
              }

              RaygunErrorStackTraceLineMessage stackTraceLineMessage = new RaygunErrorStackTraceLineMessage();
              stackTraceLineMessage.ClassName = className;
              stackTraceLineMessage.MethodName = methodName;
              lines.Add(stackTraceLineMessage);
            }
              }

              return lines.ToArray();
        }
Exemple #5
0
        private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

            if (exception.StackTrace != null)
            {
                char[] delim  = { '\r', '\n' };
                var    frames = exception.StackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in frames)
                {
                    // Trim the stack trace line
                    string stackTraceLine = line.Trim();
                    if (stackTraceLine.StartsWith("at "))
                    {
                        stackTraceLine = stackTraceLine.Substring(3);
                    }

                    string className  = stackTraceLine;
                    string methodName = null;

                    // Extract the method name and class name if possible:
                    int index = stackTraceLine.IndexOf("(");
                    if (index > 0)
                    {
                        index = stackTraceLine.LastIndexOf(".", index);
                        if (index > 0)
                        {
                            className  = stackTraceLine.Substring(0, index);
                            methodName = stackTraceLine.Substring(index + 1);
                        }
                    }

                    RaygunErrorStackTraceLineMessage stackTraceLineMessage = new RaygunErrorStackTraceLineMessage();
                    stackTraceLineMessage.ClassName  = className;
                    stackTraceLineMessage.MethodName = methodName;
                    lines.Add(stackTraceLineMessage);
                }
            }

            return(lines.ToArray());
        }
        private static RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List<RaygunErrorStackTraceLineMessage>();

              string stackTraceStr = exception.StackTrace;
              if (stackTraceStr == null)
              {
            var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 };
            lines.Add(line);
            return lines.ToArray();
              }
              try
              {
            string[] stackTraceLines = stackTraceStr.Split('\n');
            foreach (string stackTraceLine in stackTraceLines)
            {
              int lineNumber = 0;
              string fileName = null;
              string methodName = null;
              string className = null;
              string stackTraceLn = stackTraceLine.Trim();
              // Line number
              int index = stackTraceLn.LastIndexOf(":");
              if (index > 0)
              {
            bool success = int.TryParse(stackTraceLn.Substring(index + 1), out lineNumber);
            if (success)
            {
              stackTraceLn = stackTraceLn.Substring(0, index);
            }
              }
              // File name
              index = stackTraceLn.LastIndexOf("] in ");
              if (index > 0)
              {
            fileName = stackTraceLn.Substring(index + 5);
            if ("<filename unknown>".Equals(fileName))
            {
              fileName = null;
            }
            stackTraceLn = stackTraceLn.Substring(0, index);
              }

              if (!stackTraceLn.StartsWith("at (wrapper") && !stackTraceLn.StartsWith("(wrapper"))
              {
            // Method name
            index = stackTraceLn.LastIndexOf("(");
            if (index > 0)
            {
              index = stackTraceLn.LastIndexOf(".", index);
              if (index > 0)
              {
                int endIndex = stackTraceLn.IndexOf("[0x");
                if (endIndex < 0)
                {
                  endIndex = stackTraceLn.IndexOf("<0x");
                  if (endIndex < 0)
                  {
                    endIndex = stackTraceLn.Length;
                  }
                }

                methodName = stackTraceLn.Substring(index + 1, endIndex - index - 1).Trim();
                methodName = methodName.Replace(" (", "(");
                stackTraceLn = stackTraceLn.Substring(0, index);
              }
            }
            // Class name
            index = stackTraceLn.IndexOf("at ");
            if (index >= 0)
            {
              className = stackTraceLn.Substring(index + 3);
            }
              }

              if (lineNumber != 0 || !String.IsNullOrWhiteSpace(methodName) || !String.IsNullOrWhiteSpace(fileName) || !String.IsNullOrWhiteSpace(className))
              {
            var line = new RaygunErrorStackTraceLineMessage
            {
              FileName = fileName,
              LineNumber = lineNumber,
              MethodName = methodName,
              ClassName = className
            };

            lines.Add(line);
              }
              else if (!String.IsNullOrWhiteSpace(stackTraceLn))
              {
            if (stackTraceLn.StartsWith("at "))
            {
              stackTraceLn = stackTraceLn.Substring(3);
            }
            var line = new RaygunErrorStackTraceLineMessage
            {
              FileName = stackTraceLn
            };

            lines.Add(line);
              }
            }
            if (lines.Count > 0)
            {
              return lines.ToArray();
            }
              }
              catch { }

              var stackTrace = new StackTrace(exception, true);
              var frames = stackTrace.GetFrames();

              if (frames == null || frames.Length == 0)
              {
            var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 };
            lines.Add(line);
            return lines.ToArray();
              }

              foreach (StackFrame frame in frames)
              {
            MethodBase method = frame.GetMethod();

            if (method != null)
            {
              int lineNumber = frame.GetFileLineNumber();

              if (lineNumber == 0)
              {
            lineNumber = frame.GetILOffset();
              }

              var methodName = GenerateMethodName(method);

              string file = frame.GetFileName();

              string className = method.ReflectedType != null
                       ? method.ReflectedType.FullName
                       : "(unknown)";

              var line = new RaygunErrorStackTraceLineMessage
              {
            FileName = file,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
              };

              lines.Add(line);
            }
              }

              return lines.ToArray();
        }
    protected RaygunErrorStackTraceLineMessage[] ParseStackTrace(string stackTrace)
    {
      var lines = new List<RaygunErrorStackTraceLineMessage>();

      if (stackTrace == null)
      {
        return lines.ToArray();
      }

      string[] stackTraceLines = stackTrace.Split('\r', '\n');
      foreach (string stackTraceLine in stackTraceLines)
      {
        if (!String.IsNullOrEmpty(stackTraceLine))
        {
          int lineNumber = 0;
          string fileName = null;
          string methodName = null;
          string className = null;
          string stackTraceLn = stackTraceLine;
          // Line number
          int index = stackTraceLine.LastIndexOf(":line ");
          if (index > 0)
          {
            bool success = int.TryParse(stackTraceLn.Substring(index + 6), out lineNumber);
            stackTraceLn = stackTraceLn.Substring(0, index);
          }
          // File name
          index = stackTraceLn.LastIndexOf(") in ");
          if (index > 0)
          {
            fileName = stackTraceLn.Substring(index + 5);
            if ("<filename unknown>".Equals(fileName))
            {
              fileName = null;
            }
            stackTraceLn = stackTraceLn.Substring(0, index + 1);
          }
          // Method name
          index = stackTraceLn.LastIndexOf("(");
          if (index > 0)
          {
            index = stackTraceLn.LastIndexOf(".", index);
            if (index > 0)
            {
              int endIndex = stackTraceLn.LastIndexOf(")");
              if (endIndex > 0)
              {
                methodName = stackTraceLn.Substring(index + 1, endIndex - index).Trim();
                methodName = methodName.Replace(" (", "(");
                stackTraceLn = stackTraceLn.Substring(0, index);
              }
            }
          }
          // Class name
          if (methodName != null)
          {
            index = stackTraceLn.IndexOf("at ");
            if (index >= 0)
            {
              className = stackTraceLn.Substring(index + 3);
            }
          }
          else if (fileName == null)
          {
            fileName = stackTraceLine.Trim();
          }
          var line = new RaygunErrorStackTraceLineMessage
          {
            FileName = fileName,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
          };

          lines.Add(line);
        }
      }
      return lines.ToArray();
    }
        private static RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List<RaygunErrorStackTraceLineMessage>();

              #if !__UNIFIED__
              MonoTouchException mex = exception as MonoTouchException;
              if (mex != null && mex.NSException != null)
              {
            var ptr = Messaging.intptr_objc_msgSend(mex.NSException.Handle, Selector.GetHandle("callStackSymbols"));
            var arr = NSArray.StringArrayFromHandle(ptr);
            foreach (var line in arr)
            {
              lines.Add(new RaygunErrorStackTraceLineMessage { FileName = line });
            }
            return lines.ToArray();
              }
              #endif

              string stackTraceStr = exception.StackTrace;
              if (stackTraceStr == null)
              {
            var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 };
            lines.Add(line);
            return lines.ToArray();
              }
              try
              {
            string[] stackTraceLines = stackTraceStr.Split('\n');
            foreach (string stackTraceLine in stackTraceLines)
            {
              int lineNumber = 0;
              string fileName = null;
              string methodName = null;
              string className = null;
              string stackTraceLn = stackTraceLine;
              // Line number
              int index = stackTraceLine.LastIndexOf(":");
              if (index > 0)
              {
            bool success = int.TryParse(stackTraceLn.Substring(index + 1), out lineNumber);
            if (success)
            {
              stackTraceLn = stackTraceLn.Substring(0, index);
              // File name
              index = stackTraceLn.LastIndexOf("] in ");
              if (index > 0)
              {
                fileName = stackTraceLn.Substring(index + 5);
                stackTraceLn = stackTraceLn.Substring(0, index);
                // Method name
                index = stackTraceLn.LastIndexOf("(");
                if (index > 0)
                {
                  index = stackTraceLn.LastIndexOf(".", index);
                  if (index > 0)
                  {
                    int endIndex = stackTraceLn.IndexOf("[0x");
                    if (endIndex < 0)
                    {
                      endIndex = stackTraceLn.Length;
                    }
                    methodName = stackTraceLn.Substring(index + 1, endIndex - index - 1).Trim();
                    methodName = methodName.Replace(" (", "(");
                    stackTraceLn = stackTraceLn.Substring(0, index);
                  }
                }
                // Class name
                index = stackTraceLn.IndexOf("at ");
                if (index >= 0)
                {
                  className = stackTraceLn.Substring(index + 3);
                }
              }
              else
              {
                fileName = stackTraceLn;
              }
            }
            else
            {
              index = stackTraceLn.IndexOf("at ");
              if (index >= 0)
              {
                index += 3;
              }
              else
              {
                index = 0;
              }
              fileName = stackTraceLn.Substring(index);
            }
              }
              else
              {
            fileName = stackTraceLn;
              }
              var line = new RaygunErrorStackTraceLineMessage
              {
            FileName = fileName,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
              };

              lines.Add(line);
            }
            if (lines.Count > 0)
            {
              return lines.ToArray();
            }
              }
              catch { }

              var stackTrace = new StackTrace(exception, true);
              var frames = stackTrace.GetFrames();

              if (frames == null || frames.Length == 0)
              {
            var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 };
            lines.Add(line);
            return lines.ToArray();
              }

              foreach (StackFrame frame in frames)
              {
            MethodBase method = frame.GetMethod();

            if (method != null)
            {
              int lineNumber = frame.GetFileLineNumber();

              if (lineNumber == 0)
              {
            lineNumber = frame.GetILOffset();
              }

              var methodName = GenerateMethodName(method);

              string file = frame.GetFileName();

              string className = method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)";

              var line = new RaygunErrorStackTraceLineMessage
              {
            FileName = file,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
              };

              lines.Add(line);
            }
              }

              return lines.ToArray();
        }
        protected static RaygunErrorStackTraceLineMessage[] ParseStackTrace(string stackTrace)
        {
            var lines = new List<RaygunErrorStackTraceLineMessage>();

              string[] stackTraceLines = stackTrace.Split(new char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries);
              foreach (string stackTraceLine in stackTraceLines)
              {
            int lineNumber = 0;
            string fileName = null;
            string methodName = null;
            string className = null;
            string stackTraceLn = stackTraceLine;
            // Line number
            int index = stackTraceLine.LastIndexOf(":");
            if (index > 0)
            {
              bool success = int.TryParse(stackTraceLn.Substring(index + 1), out lineNumber);
              if (success)
              {
            stackTraceLn = stackTraceLn.Substring(0, index);
              }
            }
            // File name
            index = stackTraceLn.LastIndexOf("] in ");
            if (index > 0)
            {
              fileName = stackTraceLn.Substring(index + 5);
              stackTraceLn = stackTraceLn.Substring(0, index);
            }
            // Method name
            index = stackTraceLn.LastIndexOf("(");
            if (index > 0 && !stackTraceLine.StartsWith("at ("))
            {
              index = stackTraceLn.LastIndexOf(".", index);
              if (index > 0)
              {
            int endIndex = stackTraceLn.IndexOf("[0x");
            if (endIndex < 0)
            {
              endIndex = stackTraceLn.Length;
            }
            methodName = stackTraceLn.Substring(index + 1, endIndex - index - 1).Trim();
            methodName = methodName.Replace(" (", "(");
            stackTraceLn = stackTraceLn.Substring(0, index);

            // Memory address
            index = methodName.LastIndexOf("<0x");
            if (index >= 0)
            {
              fileName = methodName.Substring(index);
              methodName = methodName.Substring(0, index).Trim();
            }

            // Class name
            index = stackTraceLn.IndexOf("at ");
            if (index >= 0)
            {
              className = stackTraceLn.Substring(index + 3);
            }
              }
            }

            if (methodName == null && fileName == null)
            {
              if (!String.IsNullOrWhiteSpace(stackTraceLn) && stackTraceLn.StartsWith("at "))
              {
            stackTraceLn = stackTraceLn.Substring(3);
              }
              fileName = stackTraceLn;
            }

            if ("<filename unknown>".Equals(fileName))
            {
              fileName = null;
            }

            var line = new RaygunErrorStackTraceLineMessage
            {
              FileName = fileName,
              LineNumber = lineNumber,
              MethodName = methodName,
              ClassName = className
            };

            lines.Add(line);
              }

              return lines.ToArray();
        }
        private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List<RaygunErrorStackTraceLineMessage>();

            #if !WINRT
              var stackTrace = new StackTrace(exception, true);
              var frames = stackTrace.GetFrames();

              if (frames == null || frames.Length == 0)
              {
            var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 };
            lines.Add(line);
            return lines.ToArray();
              }

              foreach (StackFrame frame in frames)
              {
            MethodBase method = frame.GetMethod();

            if (method != null)
            {
              int lineNumber = frame.GetFileLineNumber();

              if (lineNumber == 0)
              {
            lineNumber = frame.GetILOffset();
              }

              var methodName = GenerateMethodName(method);

              string file = frame.GetFileName();

              string className = method.ReflectedType != null
                       ? method.ReflectedType.FullName
                       : "(unknown)";

              var line = new RaygunErrorStackTraceLineMessage
              {
            FileName = file,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
              };

              lines.Add(line);
            }
              }
            #else
              string[] delim = { "\r\n" };
              string stackTrace = exception.Data["Message"] as string;
              if (stackTrace != null)
              {
            var frames = stackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);

            foreach (string line in frames)
            {
              lines.Add(new RaygunErrorStackTraceLineMessage()
            {
              ClassName = line
            });
            }
              }
            #endif
              return lines.ToArray();
        }
Exemple #11
0
        protected RaygunErrorStackTraceLineMessage[] ParseStackTrace(string stackTrace)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

            string[] stackTraceLines = stackTrace.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string stackTraceLine in stackTraceLines)
            {
                int    lineNumber   = 0;
                string fileName     = null;
                string methodName   = null;
                string className    = null;
                string stackTraceLn = stackTraceLine;
                // Line number
                int index = stackTraceLine.LastIndexOf(":");
                if (index > 0)
                {
                    bool success = int.TryParse(stackTraceLn.Substring(index + 1), out lineNumber);
                    if (success)
                    {
                        stackTraceLn = stackTraceLn.Substring(0, index);
                    }
                }
                // File name
                index = stackTraceLn.LastIndexOf("] in ");
                if (index > 0)
                {
                    fileName     = stackTraceLn.Substring(index + 5);
                    stackTraceLn = stackTraceLn.Substring(0, index);
                }
                // Method name
                index = stackTraceLn.LastIndexOf("(");
                if (index > 0 && !stackTraceLine.StartsWith("at ("))
                {
                    index = stackTraceLn.LastIndexOf(".", index);
                    if (index > 0)
                    {
                        int endIndex = stackTraceLn.IndexOf("[0x");
                        if (endIndex < 0)
                        {
                            endIndex = stackTraceLn.Length;
                        }
                        methodName   = stackTraceLn.Substring(index + 1, endIndex - index - 1).Trim();
                        methodName   = methodName.Replace(" (", "(");
                        stackTraceLn = stackTraceLn.Substring(0, index);

                        // Memory address
                        index = methodName.LastIndexOf("<0x");
                        if (index >= 0)
                        {
                            fileName   = methodName.Substring(index);
                            methodName = methodName.Substring(0, index).Trim();
                        }

                        // Class name
                        index = stackTraceLn.IndexOf("at ");
                        if (index >= 0)
                        {
                            className = stackTraceLn.Substring(index + 3);
                        }
                    }
                }

                if (methodName == null && fileName == null)
                {
                    if (!String.IsNullOrWhiteSpace(stackTraceLn) && stackTraceLn.StartsWith("at "))
                    {
                        stackTraceLn = stackTraceLn.Substring(3);
                    }
                    fileName = stackTraceLn;
                }

                if ("<filename unknown>".Equals(fileName))
                {
                    fileName = null;
                }

                var line = new RaygunErrorStackTraceLineMessage
                {
                    FileName   = fileName,
                    LineNumber = lineNumber,
                    MethodName = methodName,
                    ClassName  = className
                };

                lines.Add(line);
            }

            return(lines.ToArray());
        }
        private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List<RaygunErrorStackTraceLineMessage>();

            #if WINRT
              string[] delim = { "\r\n" };
              string stackTrace = exception.StackTrace ?? exception.Data["Message"] as string;
              if (stackTrace != null)
              {
            var frames = stackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);

            foreach (string line in frames)
            {
              lines.Add(new RaygunErrorStackTraceLineMessage()
            {
              ClassName = line
            });
            }
              }
            #elif WINDOWS_PHONE
              if (exception.StackTrace != null)
              {
            char[] delim = {'\r', '\n'};
            var frames = exception.StackTrace.Split(delim);
            foreach (string line in frames)
            {
              if (!"".Equals(line))
              {
            RaygunErrorStackTraceLineMessage stackTraceLineMessage = new RaygunErrorStackTraceLineMessage();
            stackTraceLineMessage.ClassName = line;
            lines.Add(stackTraceLineMessage);
              }
            }
              }
            #else
            #if IOS
              MonoTouchException mex = exception as MonoTouchException;
              if (mex != null && mex.NSException != null)
              {
            var ptr = Messaging.intptr_objc_msgSend (mex.NSException.Handle, Selector.GetHandle ("callStackSymbols"));
            var arr = NSArray.StringArrayFromHandle (ptr);
            foreach( var line in arr)
            {
              lines.Add(new RaygunErrorStackTraceLineMessage{ FileName = line});
            }
            return lines.ToArray();
              }
            #endif
              var stackTrace = new StackTrace(exception, true);
              var frames = stackTrace.GetFrames();

              if (frames == null || frames.Length == 0)
              {
            var line = new RaygunErrorStackTraceLineMessage { FileName = "none", LineNumber = 0 };
            lines.Add(line);
            return lines.ToArray();
              }

              foreach (StackFrame frame in frames)
              {
            MethodBase method = frame.GetMethod();

            if (method != null)
            {
              int lineNumber = frame.GetFileLineNumber();

              if (lineNumber == 0)
              {
            lineNumber = frame.GetILOffset();
              }

              var methodName = GenerateMethodName(method);

              string file = frame.GetFileName();

              string className = method.ReflectedType != null
                       ? method.ReflectedType.FullName
                       : "(unknown)";

              var line = new RaygunErrorStackTraceLineMessage
              {
            FileName = file,
            LineNumber = lineNumber,
            MethodName = methodName,
            ClassName = className
              };

              lines.Add(line);
            }
              }
            #endif
              return lines.ToArray();
        }
Exemple #13
0
        protected RaygunErrorStackTraceLineMessage[] ParseStackTrace(string stackTrace)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

            if (stackTrace == null)
            {
                return(lines.ToArray());
            }

            string[] stackTraceLines = stackTrace.Split('\r', '\n');
            foreach (string stackTraceLine in stackTraceLines)
            {
                if (!String.IsNullOrEmpty(stackTraceLine))
                {
                    int    lineNumber   = 0;
                    string fileName     = null;
                    string methodName   = null;
                    string className    = null;
                    string stackTraceLn = stackTraceLine;
                    // Line number
                    int index = stackTraceLine.LastIndexOf(":line ");
                    if (index > 0)
                    {
                        bool success = int.TryParse(stackTraceLn.Substring(index + 6), out lineNumber);
                        stackTraceLn = stackTraceLn.Substring(0, index);
                    }
                    // File name
                    index = stackTraceLn.LastIndexOf(") in ");
                    if (index > 0)
                    {
                        fileName = stackTraceLn.Substring(index + 5);
                        if ("<filename unknown>".Equals(fileName))
                        {
                            fileName = null;
                        }
                        stackTraceLn = stackTraceLn.Substring(0, index + 1);
                    }
                    // Method name
                    index = stackTraceLn.LastIndexOf("(");
                    if (index > 0)
                    {
                        index = stackTraceLn.LastIndexOf(".", index);
                        if (index > 0)
                        {
                            int endIndex = stackTraceLn.LastIndexOf(")");
                            if (endIndex > 0)
                            {
                                methodName   = stackTraceLn.Substring(index + 1, endIndex - index).Trim();
                                methodName   = methodName.Replace(" (", "(");
                                stackTraceLn = stackTraceLn.Substring(0, index);
                            }
                        }
                    }
                    // Class name
                    if (methodName != null)
                    {
                        index = stackTraceLn.IndexOf("at ");
                        if (index >= 0)
                        {
                            className = stackTraceLn.Substring(index + 3);
                        }
                    }
                    else if (fileName == null)
                    {
                        fileName = stackTraceLine.Trim();
                    }
                    var line = new RaygunErrorStackTraceLineMessage
                    {
                        FileName   = fileName,
                        LineNumber = lineNumber,
                        MethodName = methodName,
                        ClassName  = className
                    };

                    lines.Add(line);
                }
            }
            return(lines.ToArray());
        }
        private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

#if WINRT
            string[] delim      = { "\r\n" };
            string   stackTrace = exception.StackTrace ?? exception.Data["Message"] as string;
            if (stackTrace != null)
            {
                var frames = stackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);

                foreach (string line in frames)
                {
                    lines.Add(new RaygunErrorStackTraceLineMessage()
                    {
                        ClassName = line
                    });
                }
            }
#elif WINDOWS_PHONE
            if (exception.StackTrace != null)
            {
                char[] delim  = { '\r', '\n' };
                var    frames = exception.StackTrace.Split(delim);
                foreach (string line in frames)
                {
                    if (!"".Equals(line))
                    {
                        RaygunErrorStackTraceLineMessage stackTraceLineMessage = new RaygunErrorStackTraceLineMessage();
                        stackTraceLineMessage.ClassName = line;
                        lines.Add(stackTraceLineMessage);
                    }
                }
            }
#else
#if IOS
            MonoTouchException mex = exception as MonoTouchException;
            if (mex != null && mex.NSException != null)
            {
                var ptr = Messaging.intptr_objc_msgSend(mex.NSException.Handle, Selector.GetHandle("callStackSymbols"));
                var arr = NSArray.StringArrayFromHandle(ptr);
                foreach (var line in arr)
                {
                    lines.Add(new RaygunErrorStackTraceLineMessage {
                        FileName = line
                    });
                }
                return(lines.ToArray());
            }
#endif
            var stackTrace = new StackTrace(exception, true);
            var frames     = stackTrace.GetFrames();

            if (frames == null || frames.Length == 0)
            {
                var line = new RaygunErrorStackTraceLineMessage {
                    FileName = "none", LineNumber = 0
                };
                lines.Add(line);
                return(lines.ToArray());
            }

            foreach (StackFrame frame in frames)
            {
                MethodBase method = frame.GetMethod();

                if (method != null)
                {
                    int lineNumber = frame.GetFileLineNumber();

                    if (lineNumber == 0)
                    {
                        lineNumber = frame.GetILOffset();
                    }

                    var methodName = GenerateMethodName(method);

                    string file = frame.GetFileName();

                    string className = method.ReflectedType != null
                       ? method.ReflectedType.FullName
                       : "(unknown)";

                    var line = new RaygunErrorStackTraceLineMessage
                    {
                        FileName   = file,
                        LineNumber = lineNumber,
                        MethodName = methodName,
                        ClassName  = className
                    };

                    lines.Add(line);
                }
            }
#endif
            return(lines.ToArray());
        }
Exemple #15
0
        private static RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

            string[] delim      = { "\r\n" };
            string   stackTrace = exception.StackTrace ?? exception.Data["Message"] as string;

            exception.Data.Remove("Message");
            if (stackTrace != null)
            {
                var frames = stackTrace.Split(delim, StringSplitOptions.RemoveEmptyEntries);

                foreach (string line in frames)
                {
                    // Trim the stack trace line
                    string stackTraceLine = line.Trim();
                    if (stackTraceLine.StartsWith("at "))
                    {
                        stackTraceLine = stackTraceLine.Substring(3);
                    }

                    int    lineNumber = 0;
                    string className  = stackTraceLine;
                    string methodName = null;
                    string fileName   = null;

                    int index = stackTraceLine.LastIndexOf(":line ", StringComparison.Ordinal);
                    if (index > 0)
                    {
                        string number = stackTraceLine.Substring(index + 6);
                        Int32.TryParse(number, out lineNumber);
                        stackTraceLine = stackTraceLine.Substring(0, index);
                    }
                    index = stackTraceLine.LastIndexOf(") in ", StringComparison.Ordinal);
                    if (index > 0)
                    {
                        fileName       = stackTraceLine.Substring(index + 5);
                        stackTraceLine = stackTraceLine.Substring(0, index + 1);
                    }
                    index = stackTraceLine.IndexOf("(", StringComparison.Ordinal);
                    if (index > 0)
                    {
                        index = stackTraceLine.LastIndexOf(".", index, StringComparison.Ordinal);
                        if (index > 0)
                        {
                            className  = stackTraceLine.Substring(0, index);
                            methodName = stackTraceLine.Substring(index + 1);
                        }
                    }

                    RaygunErrorStackTraceLineMessage stackTraceLineMessage = new RaygunErrorStackTraceLineMessage();
                    stackTraceLineMessage.ClassName  = className;
                    stackTraceLineMessage.MethodName = methodName;
                    stackTraceLineMessage.FileName   = fileName;
                    stackTraceLineMessage.LineNumber = lineNumber;
                    lines.Add(stackTraceLineMessage);
                }
            }

            return(lines.ToArray());
        }
        private RaygunErrorStackTraceLineMessage[] BuildStackTrace(Exception exception)
        {
            var lines = new List <RaygunErrorStackTraceLineMessage>();

            MonoTouchException mex = exception as MonoTouchException;

            if (mex != null && mex.NSException != null)
            {
                var ptr = Messaging.intptr_objc_msgSend(mex.NSException.Handle, Selector.GetHandle("callStackSymbols"));
                var arr = NSArray.StringArrayFromHandle(ptr);
                foreach (var line in arr)
                {
                    lines.Add(new RaygunErrorStackTraceLineMessage {
                        FileName = line
                    });
                }
                return(lines.ToArray());
            }
            string stackTraceStr = exception.StackTrace;

            if (stackTraceStr == null)
            {
                var line = new RaygunErrorStackTraceLineMessage {
                    FileName = "none", LineNumber = 0
                };
                lines.Add(line);
                return(lines.ToArray());
            }
            try
            {
                string[] stackTraceLines = stackTraceStr.Split('\n');
                foreach (string stackTraceLine in stackTraceLines)
                {
                    int    lineNumber   = 0;
                    string fileName     = null;
                    string methodName   = null;
                    string className    = null;
                    string stackTraceLn = stackTraceLine;
                    // Line number
                    int index = stackTraceLine.LastIndexOf(":");
                    if (index > 0)
                    {
                        bool success = int.TryParse(stackTraceLn.Substring(index + 1), out lineNumber);
                        if (success)
                        {
                            stackTraceLn = stackTraceLn.Substring(0, index);
                            // File name
                            index = stackTraceLn.LastIndexOf("] in ");
                            if (index > 0)
                            {
                                fileName     = stackTraceLn.Substring(index + 5);
                                stackTraceLn = stackTraceLn.Substring(0, index);
                                // Method name
                                index = stackTraceLn.LastIndexOf("(");
                                if (index > 0)
                                {
                                    index = stackTraceLn.LastIndexOf(".", index);
                                    if (index > 0)
                                    {
                                        int endIndex = stackTraceLn.IndexOf("[0x");
                                        if (endIndex < 0)
                                        {
                                            endIndex = stackTraceLn.Length;
                                        }
                                        methodName   = stackTraceLn.Substring(index + 1, endIndex - index - 1).Trim();
                                        methodName   = methodName.Replace(" (", "(");
                                        stackTraceLn = stackTraceLn.Substring(0, index);
                                    }
                                }
                                // Class name
                                index = stackTraceLn.IndexOf("at ");
                                if (index >= 0)
                                {
                                    className = stackTraceLn.Substring(index + 3);
                                }
                            }
                            else
                            {
                                fileName = stackTraceLn;
                            }
                        }
                        else
                        {
                            index = stackTraceLn.IndexOf("at ");
                            if (index >= 0)
                            {
                                index += 3;
                            }
                            else
                            {
                                index = 0;
                            }
                            fileName = stackTraceLn.Substring(index);
                        }
                    }
                    else
                    {
                        fileName = stackTraceLn;
                    }
                    var line = new RaygunErrorStackTraceLineMessage
                    {
                        FileName   = fileName,
                        LineNumber = lineNumber,
                        MethodName = methodName,
                        ClassName  = className
                    };

                    lines.Add(line);
                }
                if (lines.Count > 0)
                {
                    return(lines.ToArray());
                }
            }
            catch { }



            var stackTrace = new StackTrace(exception, true);
            var frames     = stackTrace.GetFrames();

            if (frames == null || frames.Length == 0)
            {
                var line = new RaygunErrorStackTraceLineMessage {
                    FileName = "none", LineNumber = 0
                };
                lines.Add(line);
                return(lines.ToArray());
            }

            foreach (StackFrame frame in frames)
            {
                MethodBase method = frame.GetMethod();

                if (method != null)
                {
                    int lineNumber = frame.GetFileLineNumber();

                    if (lineNumber == 0)
                    {
                        lineNumber = frame.GetILOffset();
                    }

                    var methodName = GenerateMethodName(method);

                    string file = frame.GetFileName();

                    string className = method.ReflectedType != null
                       ? method.ReflectedType.FullName
                       : "(unknown)";

                    var line = new RaygunErrorStackTraceLineMessage
                    {
                        FileName   = file,
                        LineNumber = lineNumber,
                        MethodName = methodName,
                        ClassName  = className
                    };

                    lines.Add(line);
                }
            }

            return(lines.ToArray());
        }