public CHttpLog(ICHttpLogWriter writer, HttpLogLevel alevel) { if (writer == null) { throw new ArgumentNullException("writer cannot be null"); } logWriter = writer; logLevel = alevel; }
public bool LogText(string ainformation, bool awithPrefix, HttpLogLevel alevel) { string information = ainformation; bool queued = false; if (awithPrefix) { information = LogPrefix(alevel) + " " + information; } if (alevel >= logLevel) { int repeats = 0; int waitResult = 0; bool running = runEvent.WaitOne(0, false); WaitHandle[] queueLocks = new WaitHandle[] { queueMutex, stopEvent, flushStartedEvent }; WaitHandle[] flushLocks = new WaitHandle[] { stopEvent, flushFinishedEvent }; while (running && (repeats <= logRepeats) && !queued) { waitResult = WaitHandle.WaitAny(queueLocks, logTimeout, false); if (waitResult == 0) { try { logQueue.Enqueue(new CHttpLogItem(alevel, information)); queued = true; } finally { if (logQueue.Count >= logFlushCount) { queueEvent.Set(); } queueMutex.ReleaseMutex(); } } else if (waitResult == 2) { WaitHandle.WaitAny(flushLocks, 5000, false); } repeats++; running = runEvent.WaitOne(0, false) && !stopEvent.WaitOne(0, false); } } return(queued); }
private string LogPrefix(HttpLogLevel level) { DateTime now = DateTime.Now; string levelText; string threadId = Thread.CurrentThread.ManagedThreadId.ToString("X").PadLeft(6, '0'); switch (level) { case HttpLogLevel.LogError: levelText = "-"; break; case HttpLogLevel.LogWarning: levelText = "!"; break; default: levelText = " "; break; } return(levelText + now.ToShortDateString() + " " + now.ToLongTimeString() + " " + threadId); }
public CHttpLogItem(HttpLogLevel alevel, string ainformation) { level = alevel; information = ainformation; }