private void PrintLogEntry(LogEntry result) { if (result == null) return; _messages.Add(result.Level.ToString() + " : " + result.Message); }
/// <summary> /// Perform logging ( e.g. this just keeps it in memory ) and can log out to a supplied logger. /// </summary> /// <param name="entry"></param> /// <param name="level"></param> /// <param name="message"></param> /// <param name="ex"></param> protected override void PerformLog(LogEntry entry, LogLevel level, String message, Exception ex) { _entries.Add(entry); // Trim if beyond buffer level. if (_entries.Count > _bufferLevel) { // First let callback handle the errors Flush(0, _bufferLevel); // Now remove all the items up to buffer level. _entries.RemoveRange(0, _bufferLevel); } }
protected abstract void PerformLog(LogEntry entry, LogLevel level, String message, Exception ex);
/// <summary> /// Logs debug information /// </summary> /// <param name="message">The message to log</param> /// <param name="ex">The exception</param> protected override void PerformLog(LogEntry entry, LogLevel level, string message, Exception ex) { try { // 2. store the entry. _items.Add(entry); // 3. ok to flush the entries now? if (_bufferLevel == 0) { Flush(); } else if (_bufferLevel <= _items.Count) { Flush(); } } catch (Exception) { // Can't do anything at this point. But don't let it fail the application. } }
/// <summary> /// Logs debug information /// </summary> /// <param name="message">The message to log</param> /// <param name="ex">The exception</param> public void Log(LogLevel level, string tag, string message, Exception ex) { _totalEntries++; // Not enabled. if (level < Level) return; try { // 1. create log entry LogEntry entry = new LogEntry(); entry.Message = message; entry.Level = level; entry.TimeStamp = DateTime.Now; if (ex != null) { entry.ErrorMessage = ex.Message; entry.StackTrace = ex.StackTrace; entry.Source = ex.Source; entry.Ex = ex; } PerformLog(entry, level, message, ex); } catch (Exception) { // Can't do anything at this point. But don't let it fail the application. } }