示例#1
0
        public static IEnumerable <string> FormatFieldValues(LogInspectorEntry item, ILoggingContextFormat format = null)
        {
            if (item == null)
            {
                yield break;
            }

            var timeStamp = item.TimeStamp;

            yield return(timeStamp.ToString("yyyy-MM-dd"));

            yield return(timeStamp.ToString("HH:mm:ss"));

            yield return(item.Level.ToString());

            yield return(item.LoggerName);

            yield return(item.Message);

            yield return(item.Exception?.ToString() ?? string.Empty);

            foreach (var value in FormatContextFields(item.Context, format))
            {
                yield return(value);
            }
        }
示例#2
0
        private static IEnumerable <string> FormatContextFields(
            [CanBeNull] object context,
            [CanBeNull] ILoggingContextFormat format)
        {
            if (context is ILoggingContext ctx)
            {
                return(format != null
                                               ? format.FormatContextFields(ctx)
                                               : ctx.Select(obj => obj.ToString()));
            }

            return(Enumerable.Empty <string>());
        }
示例#3
0
        public static IEnumerable <string> FormatFieldHeaders(ILoggingContextFormat format = null)
        {
            yield return("Date");

            yield return("Time");

            yield return("Level");

            yield return("Logger");

            yield return("Message");

            yield return("Exception");

            if (format?.ContextHeaders != null)
            {
                foreach (var contextHeader in format.ContextHeaders)
                {
                    yield return(contextHeader);
                }
            }
        }