1 Replies - 2041 Views - Last Post: 01 December 2012 - 07:21 AM Rate Topic: -----

#1 omrivol   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-November 12

Displaying a log file in c#

Posted 01 December 2012 - 07:14 AM

I have a log file (or actually a text file), that a certain application writing into this file.

I want to create an application in c#, that can display the log file, and can display any change in the log file dynamically.

What is the best way to to that? Any recommendation?

Is This A Good Question/Topic? 0
  • +

Replies To: Displaying a log file in c#

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6217
  • View blog
  • Posts: 21,468
  • Joined: 05-May 12

Re: Displaying a log file in c#

Posted 01 December 2012 - 07:21 AM

Assuming the other application is not locking the file for exclusive access, you can instantiate a FileWatcher that watches for changes in the file. When the event is fired, you read the contents of the file. Most log files are append only, so you only need read from the last point that you read from the previous event firing. Some log files are trimmed to a particular size, though, so you may need to backtrack through the file to find the last matching set of lines that you had previously displayed.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1