Пример #1
0
        private static string Formatter(SolaceLogState?state, Exception?exception)
        {
            var str = state?.ToJson(indent: false, ignore_null: false) ?? string.Empty;

            if (!string.IsNullOrEmpty(str) && !(exception is null))
            {
                str += " ";
            }
            str += exception?.ToString() ?? string.Empty;
            return(str);
        }
Пример #2
0
        private void JsonFormatter(LogItem item, SolaceLogState state, bool indent)
        {
            var original_foreground = Console.ForegroundColor;
            var original_background = Console.BackgroundColor;

            var json = state.ToJson(indent, ignore_null: true, json_tag: true);

            var splits = json.Split("<JSON>");

            foreach (var str in splits)
            {
                if (str.StartsWith("<$JSON>"))
                {
                    var xsplits = str.Replace("<$JSON>", string.Empty).Split("</JSON>");
                    Console.ForegroundColor = item.Configuration.Theme.JsonColor;
                    var xjson = xsplits[0];
                    if (xjson.StartsWith("\"") && xjson.EndsWith("\""))
                    {
                        xjson = xjson.TrimStart('"').TrimEnd('"');
                    }
                    Write(xjson);
                    Console.ForegroundColor = original_foreground;
                    if (xsplits.Length > 1)
                    {
                        Console.ForegroundColor = item.Configuration.Theme.MessageColor;
                        Write(xsplits[1]);
                        Console.ForegroundColor = original_foreground;
                    }
                }
                else
                {
                    Console.ForegroundColor = item.Configuration.Theme.MessageColor;
                    Write(str);
                    Console.ForegroundColor = original_foreground;
                }
            }
        }