Example #1
0
 public LogMessage[] GetLogMessages()
 {
     int numberOfMessages;
     if (newestMessageIndex < 0)
     {
         numberOfMessages = 0;
     }
     else if (newestMessageIndex >= oldestMessageIndex)
     {
         numberOfMessages = newestMessageIndex - oldestMessageIndex + 1;
     }
     else
     {
         numberOfMessages = MAX_LOG_MESSAGES;
     }
     LogMessage[] copy = new LogMessage[numberOfMessages];
     for (int i = 0; i < numberOfMessages; i++)
     {
         int index = newestMessageIndex - i;
         if (index < 0)
         {
             index = MAX_LOG_MESSAGES + index;
         }
         copy[numberOfMessages - i - 1] = store[index];
     }
     return copy;
 }
Example #2
0
 private void AddLogMessage(string message, Level l,
         Exception throwable)
 {
     if (message == null)
     {
         message = "";
     }
     string text = message;
     if (throwable != null)
     {
         text += " " + throwable.ToString();
     }
     newestMessageIndex = (newestMessageIndex + 1) % MAX_LOG_MESSAGES;
     if (newestMessageIndex == oldestMessageIndex)
     {
         store[newestMessageIndex].SetLogMessage(l, text);
         oldestMessageIndex = (oldestMessageIndex + 1) % MAX_LOG_MESSAGES;
     }
     else
     {
         store[newestMessageIndex] = new LogMessage(l, text);
         if (oldestMessageIndex < 0)
         {
             oldestMessageIndex = 0;
         }
     }
     LogMessage log = store[newestMessageIndex];
     logFormat.Out(log.time, app, log.level.levelString, log.message);
 }