/// <summary> /// Force to write remaining ContentToLog to UsingWR. /// </summary> public static void FlushImmediately() { lock (ContentToLog) { lock (LogFile) { while (ContentToLog.IsEmpty != true) { string content; if (ContentToLog.TryDequeue(out content)) { LogFile.Write(content); LogFile.Flush(); RemainContents--; if (_MAX_LOG_SIZE != -1) { if (LogFile.Length >= _MAX_LOG_SIZE) { NewLogFile(); } } } } } } }
/// <summary> /// LogWatcher, will watch ContentToLog and write them to UsingWR. /// </summary> static void LogWatcher() { IBaseWR UsingWR = LogFile; int TID = OperatingID; while (TID == OperatingID) { if (WriteToFile == true) { if (RemainContents != 0) { if (ContentToLog.IsEmpty == false) { string content; if (ContentToLog.TryDequeue(out content)) { UsingWR.Write(content); UsingWR.Flush(); RemainContents--; if (_MAX_LOG_SIZE != -1) { if (UsingWR.Length >= _MAX_LOG_SIZE) { NewLogFile(); } } } } } else { Thread.Sleep(_LOG_WATCH_INTERVAL); } } else { Thread.Sleep(_LOG_WATCH_INTERVAL); } } UsingWR.Dispose(); }