I am trying to build a little tool for our messaging (WCF) component. The idea is to give responses based on previous trace logs for testing purposes. As the SOAP messages are very big we tend to have huge trace files. What i want to do is read the traces from end to start line by line (newest to oldest) in order to build my responses. Anyone has any idea how i can do that in .NET?. It seems that FileStream class supports only forward reading.
Share
If these are text files, I have a
ReverseLineReader(or some such) in MiscUtil which you may find useful. It only supports certain encodings (Unicode, UTF-8 or any fixed-single-byte encoding) but hopefully that’ll be enough for you.It returns the strings via an iterator, so you can use LINQ to limit how many you read etc, and they’re read lazily.
I assume you don’t actually want to read the whole file? If you do, I’d suggest using
File.ReadAllLinesand then reversing the resultant array 🙂