예제 #1
0
        public string Logs(string key, int position)
        {
            ThrowIfNotSuperuser();
            Log.Add($"debug log load for {key}/{position}");
            var msg = LogHeader();

            if (History.Logs.TryGetValue(key, out var set))
            {
                if (set.Count >= position - 1)
                {
                    var log = set.Take(position).LastOrDefault();
                    msg += log == null
                        ? p("log is null")
                        : DumpTree($"Log for {key}[{position}]", log);
                }
                else
                {
                    msg += $"position ({position}) > count ({set.Count})";
                }
            }
            else
            {
                msg += $"position {position} not found in log set {key}";
            }

            msg += InsightsHtml.PageStyles();
            return(msg);
        }
예제 #2
0
        private static string ShowTime(Entry e)
        {
            if (e.Elapsed == TimeSpan.Zero)
            {
                return("");
            }
            var seconds = e.Elapsed.TotalSeconds;
            var ms      = seconds * 1000;
            var time    = ms < 1000 ? $"{ms}ms" : $"{seconds}s";

            return(InsightsHtml.HtmlEncode($" ⌚ {time} "));
        }
예제 #3
0
        private static string FormatLog(string title, ILog log)
        {
            var dump = log.Dump(" - ",
                                "",
                                "end of log",
                                ResStartPlaceholder,
                                ResEndPlaceholder,
                                withCaller: true,
                                callStart: CallerPrefixPlaceholder,
                                callEnd: CallerSuffixPlaceholder
                                );
            var htmlEnc = h1($"{title}") + "\n" + InsightsHtml.HtmlEncode(dump);

            htmlEnc = htmlEnc
                      .Replace(ResStartPlaceholder, ResStart)
                      .Replace(ResEndPlaceholder, ResEnd)
                      .Replace(CallerPrefixPlaceholder, CallerPrefix)
                      .Replace(CallerSuffixPlaceholder, CallerSuffix);

            return(ToBr(htmlEnc));
        }
예제 #4
0
        private static string TreeDumpOneLine(Entry e, string parentName)
        {
            // if it's just a close, only repeat the result
            if (e.WrapClose)
            {
                return($"{ResStart}{e.Result}{ResEnd}");
            }

            #region find perfect Label

            var label = e.Source;
            if (!string.IsNullOrEmpty(parentName) && !string.IsNullOrEmpty(e.Source))
            {
                var foundParent = e.Source?.IndexOf(parentName) ?? 0;
                if (foundParent > 0)
                {
                    var cut = foundParent + parentName.Length;
                    if (!(label.Length > cut))
                    {
                        cut = foundParent;
                    }
                    label = e.Source.Substring(cut);
                }
            }

            #endregion

            return(InsightsHtml.HoverLabel(label, e.Source, "logIds")
                   + " - "
                   + InsightsHtml.HtmlEncode(e.Message)
                   + (e.Result != null
                       ? ResStart + e.Result + ResEnd
                       : string.Empty)
                   + ShowTime(e)
                   + (e.Code != null
                       ? " " + InsightsHtml.HoverLabel("C#", $"{e.Code.Path} - {e.Code.Name}() #{e.Code.Line}", "codePeek")
                       : string.Empty)
                   + "\n");
        }