2 using System.Collections.Concurrent;
12 private readonly StreamWriter streamWriter;
13 private readonly
object lockObject =
new Object();
24 private readonly BlockingCollection<LoggerInfo> logEntries =
new BlockingCollection<LoggerInfo>();
33 fileName = String.IsNullOrWhiteSpace(fileName)
34 ? $
"{DateTime.Now.ToFileTime()}_DefaultLog.log"
35 : $
"{DateTime.Now.ToFileTime()}_{Path.GetFileName(fileName)}.log";
36 this.streamWriter =
new StreamWriter(Path.Combine(folder, fileName));
52 if (this.streamWriter == null)
55 lock (this.lockObject)
57 this.streamWriter.Close();
69 lock (this.lockObject)
71 this.streamWriter.WriteLine(logInfo.
ToString());
72 this.streamWriter.Flush();
82 this.logEntries.Add(loggerInfo);
91 this.logEntries.Add(null);
void EnqueueObject(LoggerInfo loggerInfo)
Enqueues the object.
Class for holding log information
LoggerTask(string folder, string fileName)
Initializes a new instance of the LoggerTask class.
void Stop()
Stops this instance.
bool IsStopped
Gets a value indicating whether this instance is stopped.
void DoWork()
Does the work. Events to log are filled in a concurrent queue and then read here in serial order...
override string ToString()
Returns a System.String that represents this instance.