NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Common.Log.TextLog Class Referenceabstract
Inheritance diagram for Ntp.Common.Log.TextLog:
Collaboration diagram for Ntp.Common.Log.TextLog:

Public Member Functions

override void Initialize ()
 
override void Resume ()
 
override void Suspend ()
 
override void WriteLine (string text, Severity severity)
 
override void WriteLine (Exception exception)
 
override void WriteLine (Exception exception, Severity severity)
 
- Public Member Functions inherited from Ntp.Common.Log.LogBase
abstract void Close ()
 

Protected Member Functions

 TextLog (Severity threshold, string timeFormat)
 
abstract TextWriter CreateWriter ()
 
- Protected Member Functions inherited from Ntp.Common.Log.LogBase
 LogBase (Severity threshold, bool isSysLog=false)
 

Protected Attributes

bool Closed
 
bool Initialized
 
readonly object Locker = new object()
 

Properties

bool ShowSeverity [get, set]
 
bool ShowTimeStamp [get, set]
 
- Properties inherited from Ntp.Common.Log.LogBase
bool IsSysLog [get]
 
Severity Threshold [get]
 

Private Attributes

readonly List< string > cache = new List<string>()
 
bool suspended
 
readonly string timeFormat
 
TextWriter writer
 

Detailed Description

Definition at line 28 of file TextLog.cs.

Constructor & Destructor Documentation

Ntp.Common.Log.TextLog.TextLog ( Severity  threshold,
string  timeFormat 
)
inlineprotected

Definition at line 30 of file TextLog.cs.

31  : base(threshold)
32  {
33  this.timeFormat = timeFormat;
34  Initialized = false;
35  suspended = false;
36  }
readonly string timeFormat
Definition: TextLog.cs:41

Member Function Documentation

abstract TextWriter Ntp.Common.Log.TextLog.CreateWriter ( )
protectedpure virtual
override void Ntp.Common.Log.TextLog.Initialize ( )
inlinevirtual

Implements Ntp.Common.Log.LogBase.

Definition at line 51 of file TextLog.cs.

52  {
53  lock (Locker)
54  {
55  if (!Initialized && !suspended && !Closed)
56  {
57  writer = CreateWriter();
58  Initialized = true;
59  }
60  }
61  }
readonly object Locker
Definition: TextLog.cs:40
abstract TextWriter CreateWriter()
TextWriter writer
Definition: TextLog.cs:45
override void Ntp.Common.Log.TextLog.Resume ( )
inlinevirtual

Implements Ntp.Common.Log.LogBase.

Definition at line 63 of file TextLog.cs.

64  {
65  lock (Locker)
66  {
67  suspended = false;
68  }
69  }
readonly object Locker
Definition: TextLog.cs:40
override void Ntp.Common.Log.TextLog.Suspend ( )
inlinevirtual

Implements Ntp.Common.Log.LogBase.

Definition at line 71 of file TextLog.cs.

72  {
73  lock (Locker)
74  {
75  if (writer != null)
76  {
77  writer.Close();
78  writer.Dispose();
79  writer = null;
80  }
81  Initialized = false;
82  suspended = true;
83  }
84  }
readonly object Locker
Definition: TextLog.cs:40
TextWriter writer
Definition: TextLog.cs:45
override void Ntp.Common.Log.TextLog.WriteLine ( string  text,
Severity  severity 
)
inlinevirtual

Implements Ntp.Common.Log.LogBase.

Definition at line 86 of file TextLog.cs.

Referenced by Ntp.Common.Log.LogGroup.WriteLine().

87  {
88  if (!Initialized)
89  Initialize();
90 
91  if (!Initialized)
92  return;
93 
94  lock (Locker)
95  {
96  if (Initialized && !suspended && cache.Count != 0)
97  {
98  foreach (string line in cache)
99  {
100  writer.WriteLine(line);
101  }
102  writer.Flush();
103  cache.Clear();
104  }
105  }
106 
107  if (severity < Threshold)
108  return;
109 
110  string severityText = string.Empty;
111 
112  if (ShowSeverity)
113  {
114  string pad = string.Empty;
115 
116  switch (severity)
117  {
118  case Severity.Error:
119  severityText = "ERROR";
120  break;
121  case Severity.Warn:
122  severityText = "WARN";
123  pad = " ";
124  break;
125  case Severity.Notice:
126  severityText = "NOTICE";
127  break;
128  case Severity.Info:
129  severityText = "INFO";
130  pad = " ";
131  break;
132  case Severity.Debug:
133  severityText = "DEBUG";
134  break;
135  case Severity.Trace:
136  severityText = "TRACE";
137  break;
138  default:
139  throw new ApplicationException("Unknown severity level.");
140  }
141 
142  severityText = string.Concat(" [", severityText, "] ", pad);
143  }
144 
145  DateTime now = DateTime.Now;
146 
147  string stamp =
148  ShowTimeStamp && timeFormat != null
149  ? now.ToString(timeFormat)
150  : string.Empty;
151 
152  string entry = string.Concat(stamp, severityText, text);
153 
154  lock (Locker)
155  {
156  if (Initialized)
157  {
158  writer.WriteLine(entry);
159  writer.Flush();
160  }
161  else
162  {
163  cache.Add(entry);
164  }
165  }
166  }
readonly List< string > cache
Definition: TextLog.cs:38
override void Initialize()
Definition: TextLog.cs:51
readonly object Locker
Definition: TextLog.cs:40
Severity Threshold
Definition: LogBase.cs:34
TextWriter writer
Definition: TextLog.cs:45
readonly string timeFormat
Definition: TextLog.cs:41

Here is the caller graph for this function:

override void Ntp.Common.Log.TextLog.WriteLine ( Exception  exception)
inlinevirtual

Implements Ntp.Common.Log.LogBase.

Definition at line 168 of file TextLog.cs.

169  {
170  WriteLine(exception.Message, Severity.Error);
171  WriteLine(exception.StackTrace, Severity.Debug);
172  }
override void WriteLine(string text, Severity severity)
Definition: TextLog.cs:86
override void Ntp.Common.Log.TextLog.WriteLine ( Exception  exception,
Severity  severity 
)
inlinevirtual

Implements Ntp.Common.Log.LogBase.

Definition at line 174 of file TextLog.cs.

175  {
176  if (severity < Threshold)
177  return;
178 
179  WriteLine(exception.Message, severity);
180  WriteLine(exception.StackTrace, severity);
181  }
Severity Threshold
Definition: LogBase.cs:34
override void WriteLine(string text, Severity severity)
Definition: TextLog.cs:86

Member Data Documentation

readonly List<string> Ntp.Common.Log.TextLog.cache = new List<string>()
private

Definition at line 38 of file TextLog.cs.

bool Ntp.Common.Log.TextLog.Closed
protected

Definition at line 42 of file TextLog.cs.

bool Ntp.Common.Log.TextLog.Initialized
protected

Definition at line 43 of file TextLog.cs.

readonly object Ntp.Common.Log.TextLog.Locker = new object()
protected

Definition at line 40 of file TextLog.cs.

bool Ntp.Common.Log.TextLog.suspended
private

Definition at line 44 of file TextLog.cs.

readonly string Ntp.Common.Log.TextLog.timeFormat
private

Definition at line 41 of file TextLog.cs.

TextWriter Ntp.Common.Log.TextLog.writer
private

Definition at line 45 of file TextLog.cs.

Property Documentation

bool Ntp.Common.Log.TextLog.ShowSeverity
getset

Definition at line 49 of file TextLog.cs.

bool Ntp.Common.Log.TextLog.ShowTimeStamp
getset

Definition at line 47 of file TextLog.cs.


The documentation for this class was generated from the following file: