Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6423


Ignore:
Timestamp:
06/16/11 10:30:26 (13 years ago)
Author:
cneumuel
Message:

#1546 added optional limit to log

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Log.cs

    r5445 r6423  
    4343    }
    4444
     45    [Storable]
     46    protected long maxMessageCount;
     47    public virtual long MaxMessageCount {
     48      get { return maxMessageCount; }
     49    }
     50
    4551    [StorableConstructor]
    4652    protected Log(bool deserializing) : base(deserializing) { }
    4753    protected Log(Log original, Cloner cloner)
    4854      : base(original, cloner) {
    49       messages = new List<string>(original.messages);
     55      this.messages = new List<string>(original.messages);
     56      this.maxMessageCount = original.maxMessageCount;
    5057    }
    51     public Log()
     58    public Log(long maxMessageCount = -1)
    5259      : base() {
    53       messages = new List<string>();
     60      this.messages = new List<string>();
     61      this.maxMessageCount = maxMessageCount;
    5462    }
    5563
     
    6573      string s = DateTime.Now.ToString() + "\t" + message;
    6674      messages.Add(s);
     75      CapMessages();
    6776      OnMessageAdded(s);
    6877    }
     
    7079      string s = DateTime.Now.ToString() + "\t" + "Exception occurred:" + Environment.NewLine + ErrorHandling.BuildErrorMessage(ex);
    7180      messages.Add(s);
     81      CapMessages();
    7282      OnMessageAdded(s);
     83    }
     84    protected virtual void CapMessages() {
     85      while (maxMessageCount >= 0 && messages.Count > maxMessageCount) {
     86        messages.RemoveAt(0);
     87      }
    7388    }
    7489
Note: See TracChangeset for help on using the changeset viewer.