0

Scenario is the following:

  • A (weather) service dumps sensor data into a log file/text file.
  • The new readings are appended to the bottom of a given (existing) file
  • New data is added at regular intervals (interval may or may not be known)

I need to parse the new information/line and send it off to another service.

I don't want to read the whole file every time, unless I have to.

EDIT: Sorry for the bad wording. "unless I have to" should be understood as if there is no other way around. I have seen the post/answer referenced and it seems a little extensive.

Framework is 4.5.x.

Thank you.

Karsten Strøbæk
  • 643
  • 2
  • 8
  • 17

1 Answers1

2

To get the the last line of a text file you can use this

File.ReadLines(myFileName).Last();

This is the simplest method, but is inefficient. You can write your own parser as show here

Community
  • 1
  • 1
David Pilkington
  • 13,528
  • 3
  • 41
  • 73