MarkerTag CreateCodeLocationMarkerTag()
        {
            CodeLocation location  = new CodeLocation();
            Marker       marker    = Marker.CodeLocation(location);
            MarkerTag    markerTag = new MarkerTag(marker);

            markerTag.Contents.Add(CreateCodeLocationTextTag());
            return(markerTag);
        }
示例#2
0
        /// <summary>
        /// Writes the stack trace in a structured format with markers to distinguish its component elements.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The stack trace will not be terminated by a new line.
        /// </para>
        /// </remarks>
        /// <param name="writer">The log stream writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (IsEmpty)
            {
                return;
            }

            using (writer.BeginMarker(Marker.StackTrace))
            {
                int pos = 0;
                foreach (Match match in StackFrameRegex.Matches(stackTrace))
                {
                    if (match.Index != pos)
                    {
                        writer.Write(stackTrace.Substring(pos, match.Index - pos));
                    }

                    string prefix = match.Groups["prefix"].Value;
                    writer.Write(prefix);

                    string path = match.Groups["path"].Value;
                    int    line;
                    int.TryParse(match.Groups["line"].Value, NumberStyles.None, CultureInfo.InvariantCulture, out line);

                    using (writer.BeginMarker(Marker.CodeLocation(new CodeLocation(path, line, 0))))
                        writer.Write(match.Value.Substring(prefix.Length));

                    pos = match.Index + match.Length;
                }

                if (pos < stackTrace.Length)
                {
                    writer.Write(stackTrace.Substring(pos));
                }
            }
        }