Пример #1
0
        /// <summary>
        /// Formats a log list entry.
        /// </summary>
        /// <para/>
        /// If the key is null, writes just the values.
        /// <param name="entry">Log entry.</param>
        /// <param name="renderer">Renderer for log data.</param>
        private void FormatEntry(LogList entry, IDataRenderer renderer)
        {
            if (!string.IsNullOrEmpty(entry.Key))
            {
                renderer.RenderKey(entry.Key)
                .RenderInvariant(KeyValueSeparator);
            }

            renderer.RenderInvariant(ListOpening);

            if (entry.Entries.Count > 0)
            {
                foreach (var value in entry.Entries)
                {
                    if (value is ILogEntry)
                    {
                        FormatEntry((ILogEntry)value, renderer);
                    }
                    else
                    {
                        renderer.RenderValue(value.ToString());
                    }

                    renderer.RenderInvariant(ListItemSeparator);
                }

                renderer.RemoveLastCharacter(); // Removes the last separator.
            }

            renderer.RenderInvariant(ListClosing);
        }
Пример #2
0
        /// <inheritdoc />
        public string Format(LogLevelName level, List <ILogEntry> entries, IDataRenderer renderer)
        {
            FormatDate(TimeProvider.Now, renderer);
            FormatLevel(level, renderer);

            foreach (var entry in entries)
            {
                FormatEntry(entry, renderer);
                renderer.RenderInvariant(EntrySeparator);
            }
            renderer.RemoveLastCharacter(); // Removes the last separator.

            return(renderer.Render());
        }
Пример #3
0
        /// <summary>
        /// Formats a log object entry.
        /// </summary>
        /// <para/>
        /// If the key is null, writes just the values.
        /// <param name="entry">Log entry.</param>
        /// <param name="renderer">Renderer for log data.</param>
        private void FormatEntry(LogObject entry, IDataRenderer renderer)
        {
            if (!string.IsNullOrEmpty(entry.Key))
            {
                renderer.RenderKey(entry.Key)
                .RenderInvariant(KeyValueSeparator);
            }

            renderer.RenderInvariant(ObjectOpening);

            if (entry.Entries.Count > 0)
            {
                foreach (var value in entry.Entries)
                {
                    FormatEntry(value, renderer);
                    renderer.RenderInvariant(EntrySeparator);
                }

                renderer.RemoveLastCharacter(); // Removes the last separator.
            }

            renderer.RenderInvariant(ObjectClosing);
        }
Пример #4
0
 /// <summary>
 /// Formats the log level in the log.
 /// </summary>
 /// <param name="entry">Log entry.</param>
 /// <param name="renderer">Renderer for log data.</param>
 private void FormatEntry(LogException entry, IDataRenderer renderer)
 {
     renderer.RemoveLastCharacter() // Always remove the last entry separator.
     .RenderInvariant(Environment.NewLine)
     .RenderException(entry.Details);
 }