public static LogEntryStrackFrame FromStackFrame(StackFrame stackFrame)
        {
            if (stackFrame == null)
            {
                return(Empty);
            }

            try
            {
                LogEntryStrackFrame result = new LogEntryStrackFrame();
                result._rawStackFrame = LogFormat.StackFrame(stackFrame);
                result._fileName      = stackFrame.GetFileName();
                result._lineNumber    = stackFrame.GetFileLineNumber();

                MethodBase method = stackFrame.GetMethod();
                if (method != null)
                {
                    result._declaringTypeName   = method.DeclaringType.FullName;
                    result._methodName          = method.Name;
                    result._methodSignatureHash = GetMethodSignatureHash(method);
                }

                return(result);
            }
            catch (Exception e)
            {
                LogEntryStrackFrame result = new LogEntryStrackFrame();
                result._rawStackFrame = "Error: " + e.GetType().Name;
                return(result);
            }
        }
        public static LogEntryStrackFrame FromUnityBuildMessage(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                return(Empty);
            }
            try
            {
                // Parsing "Assets/Editor/LogEditorWindow.cs(36,15): error CS1519: ..."
                MatchCollection matches = regexUnityBuildMessage.Matches(message);
                if (matches.Count == 0)
                {
                    return(Empty);
                }

                LogEntryStrackFrame result = new LogEntryStrackFrame();
                result._rawStackFrame = message.Replace("{", "{{").Replace("}", "}}");
                result._fileName      = matches[0].Groups[1].Value;
                result._lineNumber    = Convert.ToInt32(matches[0].Groups[2].Value);
                return(result);
            }
            catch (Exception e)
            {
                LogEntryStrackFrame result = new LogEntryStrackFrame();
                result._rawStackFrame = "Error: " + e.GetType().Name;
                return(result);
            }
        }
Beispiel #3
0
        public static LogEntryStrackTrace FromStackTrace(StackTrace stackTrace)
        {
            if (stackTrace == null)
            {
                return(Empty);
            }
            if (stackTrace.FrameCount == 0)
            {
                return(Empty);
            }

            try
            {
                LogEntryStrackTrace result = new LogEntryStrackTrace();
                StackFrame[]        frames = stackTrace.GetFrames();

                // Skip all frames within the logging framework itself
                int skipFrames = 0;
                for (int i = 0; i < frames.Length; i++)
                {
                    MethodBase method        = frames[i].GetMethod();
                    Type       type          = method.DeclaringType;
                    bool       isLoggingType =
                        !string.IsNullOrEmpty(type.Namespace) &&
                        type.Namespace.StartsWith(typeof(Log).Namespace);

                    // Select the first stack frame that is not part of the
                    // logging code, which is defined as everything in the
                    // same namespace as the Log class
                    if (isLoggingType)
                    {
                        skipFrames++;
                    }
                    else
                    {
                        break;
                    }
                }

                if (skipFrames < frames.Length)
                {
                    result._frames = new LogEntryStrackFrame[frames.Length - skipFrames];
                    for (int i = skipFrames; i < frames.Length; i++)
                    {
                        result._frames[i - skipFrames] = LogEntryStrackFrame.FromStackFrame(frames[i]);
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                return(Error);
            }
        }
Beispiel #4
0
        public static LogEntryStrackTrace FromUnityStackTrace(string stackTrace, string message)
        {
            try
            {
                // Do we have an actual stack trace from Unity? Parse it.
                if (!string.IsNullOrEmpty(stackTrace))
                {
                    string[] lines = stackTrace.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

                    // Skip stack frames within Unity's own Debug class
                    int skipLines = 0;
                    while (skipLines < lines.Length && lines[skipLines].StartsWith("UnityEngine.Debug:", StringComparison.InvariantCultureIgnoreCase))
                    {
                        skipLines++;
                    }

                    LogEntryStrackTrace result = new LogEntryStrackTrace();
                    if (skipLines < lines.Length)
                    {
                        result._frames = new LogEntryStrackFrame[lines.Length - skipLines];
                        for (int i = skipLines; i < lines.Length; i++)
                        {
                            result._frames[i - skipLines] = LogEntryStrackFrame.FromUnityStackFrame(lines[i]);
                        }
                    }

                    return(result);
                }
                // Otherwise, try to parse the message in order to obtain a stack frame.
                // This will trigger for Unity reporting build errors.
                else if (!string.IsNullOrEmpty(message))
                {
                    LogEntryStrackTrace result = new LogEntryStrackTrace();
                    result._frames    = new LogEntryStrackFrame[1];
                    result._frames[0] = LogEntryStrackFrame.FromUnityBuildMessage(message);
                    return(result);
                }
                else
                {
                    return(Empty);
                }
            }
            catch (Exception)
            {
                return(Error);
            }
        }
        public static LogEntryStrackFrame FromUnityStackFrame(string stackFrame)
        {
            if (string.IsNullOrEmpty(stackFrame))
            {
                return(Empty);
            }
            try
            {
                // Parsing "Namespace.Foo+Nested.Bar () (at Assets/Code/Editor.cs:298)"
                MatchCollection matches = regexUnityStackFrameWithFile.Matches(stackFrame);
                if (matches.Count == 0)
                {
                    // Parsing "Namespace.Foo+Nested.Bar ()"
                    matches = regexUnityStackFrame.Matches(stackFrame);
                }
                if (matches.Count == 0)
                {
                    return(Empty);
                }

                string   methodParams     = matches[0].Groups[3].Value;
                string[] methodParamToken = methodParams.Split(',');
                for (int i = 0; i < methodParamToken.Length; i++)
                {
                    methodParamToken[i] = methodParamToken[i].Split('`')[0].Trim();
                }

                LogEntryStrackFrame result = new LogEntryStrackFrame();
                result._rawStackFrame     = stackFrame;
                result._declaringTypeName = matches[0].Groups[1].Value;
                result._methodName        = matches[0].Groups[2].Value;
                if (matches[0].Groups.Count > 5)
                {
                    result._fileName   = matches[0].Groups[4].Value;
                    result._lineNumber = Convert.ToInt32(matches[0].Groups[5].Value);
                }
                result._methodSignatureHash = GetMethodSignatureHash(methodParamToken);
                return(result);
            }
            catch (Exception e)
            {
                LogEntryStrackFrame result = new LogEntryStrackFrame();
                result._rawStackFrame = "Error: " + e.GetType().Name;
                return(result);
            }
        }