コード例 #1
0
ファイル: TextLogWriter.cs プロジェクト: adina-iliescu/logjam
 /// <summary>
 /// Central method to format and write <paramref name="entry" /> to the <see cref="FormatWriter" />.
 /// </summary>
 /// <typeparam name="TEntry">The log entry type</typeparam>
 /// <param name="entry">The log entry</param>
 /// <param name="entryFormatter">The <see cref="EntryFormatter{TEntry}" /></param>
 protected virtual void WriteFormattedEntry <TEntry>(ref TEntry entry, EntryFormatter <TEntry> entryFormatter)
     where TEntry : ILogEntry
 {
     if (IsStarted && _formatWriter.IsEnabled)
     {
         entryFormatter.Format(ref entry, _formatWriter);
         if (AutoFlush)
         {
             _formatWriter.Flush();
         }
     }
 }
コード例 #2
0
ファイル: TextLogWriter.cs プロジェクト: adina-iliescu/logjam
        /// <summary>
        /// Adds the specified <typeparamref name="TEntry" /> to this <see cref="TextWriterLogWriter" />, using
        /// <paramref name="entryFormatter" /> to
        /// format entries of type <c>TEntry</c>.
        /// </summary>
        /// <typeparam name="TEntry"></typeparam>
        /// <param name="entryFormatter"></param>
        /// <returns>this, for chaining calls in fluent style.</returns>
        // TODO: Rename to .IncludeEntry or .AddEntry or similar?
        public TextLogWriter AddFormat <TEntry>(EntryFormatter <TEntry> entryFormatter = null)
            where TEntry : ILogEntry
        {
            if (entryFormatter == null)
            { // Try creating the default entry formatter
                entryFormatter = DefaultFormatterAttribute.GetDefaultFormatterFor <TEntry>();
                if (entryFormatter == null)
                {
                    throw new ArgumentNullException(nameof(entryFormatter),
                                                    $"No [DefaultFormatter] attribute could be found for entry type {typeof(TEntry).FullName}, so {nameof(entryFormatter)} argument must be set.");
                }
            }

            AddEntryWriter(new InnerEntryWriter <TEntry>(this, entryFormatter));
            return(this);
        }
コード例 #3
0
ファイル: TextLogWriter.cs プロジェクト: adina-iliescu/logjam
 public InnerEntryWriter(TextLogWriter parent, EntryFormatter <TEntry> entryFormatter)
 {
     _parent    = parent;
     _formatter = entryFormatter;
 }