23 using System.Collections.Generic;
26 namespace Ntp.Common.Log
33 this.timeFormat = timeFormat;
38 private readonly List<string> cache =
new List<string>();
40 protected readonly
object Locker =
new object();
47 public bool ShowTimeStamp {
get;
set; }
49 public bool ShowSeverity {
get;
set; }
55 if (!Initialized && !suspended && !Closed)
57 writer = CreateWriter();
96 if (Initialized && !suspended && cache.Count != 0)
98 foreach (
string line
in cache)
100 writer.WriteLine(line);
107 if (severity < Threshold)
110 string severityText =
string.Empty;
114 string pad =
string.Empty;
119 severityText =
"ERROR";
122 severityText =
"WARN";
126 severityText =
"NOTICE";
129 severityText =
"INFO";
133 severityText =
"DEBUG";
136 severityText =
"TRACE";
139 throw new ApplicationException(
"Unknown severity level.");
142 severityText =
string.Concat(
" [", severityText,
"] ", pad);
145 DateTime now = DateTime.Now;
148 ShowTimeStamp && timeFormat != null
149 ? now.ToString(timeFormat)
152 string entry =
string.Concat(stamp, severityText, text);
158 writer.WriteLine(entry);
170 WriteLine(exception.Message,
Severity.Error);
171 WriteLine(exception.StackTrace,
Severity.Debug);
176 if (severity < Threshold)
179 WriteLine(exception.Message, severity);
180 WriteLine(exception.StackTrace, severity);
183 protected abstract TextWriter CreateWriter();
override void Initialize()
override void WriteLine(Exception exception, Severity severity)
override void WriteLine(Exception exception)
override void WriteLine(string text, Severity severity)
TextLog(Severity threshold, string timeFormat)
readonly string timeFormat