public static SolaceLogState Create(string message, object[] args) { var elms = new List <StateElement>(args.Length); var count = 0; foreach (var item in args) { var elm = new StateElement(count, item); elms.Add(elm); count++; } var state = new SolaceLogState(message, elms); return(state); }
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; } } }
private static void RawLog(LogLevel level, ILogger logger, Exception?exception, string message, params object[] args) { logger.Log <SolaceLogState>(level, GetId(logger), SolaceLogState.Create(message, args), exception, Formatter); }