Beispiel #1
0
        /// <inheritdoc cref="Format(LogEvent,TextWriter,OutputTemplate,IFormatProvider)"/>
        public static string Format(
            [NotNull] LogEvent @event,
            [NotNull] OutputTemplate template,
            [CanBeNull] IFormatProvider formatProvider = null)
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            var builder = StringBuilderCache.Acquire(template.ToString().Length + @event.MessageTemplate?.Length ?? 0);
            var writer  = new StringWriter(builder);

            Format(@event, writer, template, formatProvider);

            StringBuilderCache.Release(builder);

            return(builder.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// <para>Renders given <paramref name="event"/> using all of its content.</para>
        /// <para>Performs substitution of property placeholders present in <paramref name="template"/>.</para>
        /// <para>Uses template syntax defined for <see cref="OutputTemplate"/>.</para>
        /// <para>Example output template: <c>{Timestamp} {Level} {Prefix} {Message}{NewLine}{Exception}</c></para>
        /// </summary>
        public static void Format(
            [NotNull] LogEvent @event,
            [NotNull] TextWriter writer,
            [NotNull] OutputTemplate template,
            [CanBeNull] IFormatProvider formatProvider = null)
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            foreach (var token in template.Tokens)
            {
                token.Render(@event, writer, formatProvider);
            }
        }