C # - Best Strategy for Implementing the Player for Large Text Files


We have an application which logs its processing steps into text files. These files are used during implementation and testing to analyse problems. Each file is up to 10MB in size and contains up to 100,000 text lines. Currently the analysis of these logs is done by opening a text viewer (Notepad++ etc) and looking for specific strings and data depending on the problem.

I am building an application which will help the analysis. It will enable a user to read files, search, highlight specific strings and other specific operations related to isolating relevant text. The files will not be edited!

While playing a little with some concepts, I found out immediately that TextBox (or RichTextBox) don't handle display of large text very well. I managed to to implement a viewer using DataGridView with acceptable performance, but that control does not support color highlighting of specific strings.

I am now thinking of holding the entire text file in memory as a string, and only displaying a very limited number of records in the RichTextBox. For scrolling and navigating I thought of adding an independent scrollbar.

One problem I have with this approach is how to get specific lines from the stored string.

If anyone has any ideas, can highlight problems with my approach then thank you

I would suggest loading the whole thing into memory, but as a collection of strings rather than a single string. It's very easy to do that:

string[] lines = File.ReadAllLines("file.txt");

Then you can search for matching lines with LINQ, display them easily etc.