Hi,
I'm trying to implement a log viewer in my application. The idea is simple, a listbox that shows some messages sended from other classes, but I don't know what is the best way to do this.
My initial thought was to make a Logger class (singletone) that contains a List or Queue, then I'll add a method AddMessage(string s) or something like that. When this method is called it will add the message to the list or queue and it will fire a NewMessage event. This event is because I don't think that is a good idea to check the list every some amount of time. The sequence of messages could be 3 consecutives, then 40 minutes without nothing, then a few more ...
So, in my form class (or wherever I want to receive the messages) I will listen to this event to empty the list or queue (this is because I should be able to send messages even when the listbox (final receptor) has not been created). The idea of the list is to save messages when no one is listening the event.
Also, i've put a restriction of 300 messages... so the oldest ones will be deleted everytime i'm going to add new ones... something like this:
while(listbox.Items.Count > 300)
{
listbox.Items.RemoveAt(0);
}
Do you think that this is the best approach?
Thanks for your time. Best regards.
Edit 1: I don't want to use another framework.
Edit 2: STOP suggesting frameworks or another application. I want to learn the logic behind, and if what i was proposing is right or wrong!