public void Log(CLog.LogData logData) { lock (this.mLogLock) { this.mWaitingLogQueue.Enqueue(logData); Monitor.Pulse(this.mLogLock); } }
void WriteLog() { while (this.mIsRunning) { if (this.mWritingLogQueue.Count == 0) { lock (this.mLogLock) { while (this.mWaitingLogQueue.Count == 0) { Monitor.Wait(this.mLogLock); } Queue <CLog.LogData> tmpQueue = this.mWritingLogQueue; this.mWritingLogQueue = this.mWaitingLogQueue; this.mWaitingLogQueue = tmpQueue; } } else { while (this.mWritingLogQueue.Count > 0) { CLog.LogData log = this.mWritingLogQueue.Dequeue(); if (log.Level == CLog.LogLevel.ERROR) { this.mLogWriter.WriteLine("---------------------------------------------------------------------------------------------------------------------"); this.mLogWriter.WriteLine(System.DateTime.Now.ToString() + "\t" + log.Log + "\n"); this.mLogWriter.WriteLine(log.Track); this.mLogWriter.WriteLine("---------------------------------------------------------------------------------------------------------------------"); } else { this.mLogWriter.WriteLine(System.DateTime.Now.ToString() + "\t" + log.Log); } } } } }