Reverse Streamreader

I have an application after which I was assigned to clean up. The application itself is relatively simple - it executes a SQL query, uses a web service and displays the results in a log file. My task is to archive files on our NAS after the application is executed with them. It locks files exclusively until they are executed with them, so it will add a bit of complexity. I also can’t touch the application, just the logs. Anyway, my application is pretty simple:

  • Check if you can open the file (catch IOException) and mark it as available in bool [] if no exception is thrown.
  • After going through an array of files marked true, read each line of the file in StreamReader using the ReadLine method. Since the application sometimes hiccups and does not end, I cannot just use the IOException to find out if the file is complete - I have to parse the text.
  • If the text indicating completion is found, write the file, upload the archive file to the NAS and delete the original.

My code works, it is very laborious (log files are about 500 MB). My thoughts on improving include starting my search from the bottom of the file, and not from the top, but StreamReader does not support this method. I can not use the ReadToEnd method and then read back, because it just throws an exception from memory. Any thoughts on the way I could speed up parsing the log file?

+5
1

, , , ? , , , , 3 ..

, FileStream, Seek , , , .

-3 ,

// Seek -3 bytes starting from the end of the file
fileStream.Seek(-3, SeekOrigin.End);
+6

All Articles