bmt22033
bmt22033

Reputation: 7250

Displaying log file in a multiline textbox

I'm writing data to a log file and need to display that data in my WinForms UI. My initial thought was to use a multiline textbox like this:

private void UpdateUITextbox(string text)
{
    textBoxStatus.AppendText(text + Environment.NewLine);
}

I don't write a huge amount of text to my log file but over time, it's going to add up and I'll probably end up exceeding whatever the default maxlength for a multiline textbox is. The only thing I can think of to do to prevent this from happening is to hook into the OnKeyPress event handler and check the length of the textbox before I add something to it and, when necessary, to remove the older text to make room for the newer text. But this seems like it would definitely have an impact on performance. Someone please tell me that there is a better way to do this?

Upvotes: 0

Views: 3169

Answers (3)

Hossein
Hossein

Reputation: 26004

Instead of a multi-line text box why don't you use a list box ?
And for the log, its best to add more information to your logs while saving them such as the time.
And on the load read each line which has a date stamp in the range you think is fairly recent. It is not wise to to load all of your log files just at once. load only the new ones.
If you need to see the older logs,You can still manage that using the time/date stamp solution.

Upvotes: 0

dcstraw
dcstraw

Reputation: 3311

We show our log using AvalonEdit. It scales very well up to hundreds of thousands of lines.

Upvotes: 0

zmbq
zmbq

Reputation: 39023

A Winforms TextBox has a maximum length of 2GB.

You'll have to worry about usability long before you worry about memory issues - if the log is too long, your users are not going to be able to use it effectively.

Upvotes: 2

Related Questions