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

#1 omrivol  Icon 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

Hello,
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?

Thanks!
Is This A Good Question/Topic? 0
  • +

Replies To: Displaying a log file in c#

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,159
  • 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