Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sample C# project Pin
Mycroft Holmes25-Sep-11 16:15
professionalMycroft Holmes25-Sep-11 16:15 
AnswerRe: Sample C# project Pin
Abhinav S25-Sep-11 18:33
Abhinav S25-Sep-11 18:33 
AnswerRe: Sample C# project Pin
Richard MacCutchan25-Sep-11 23:12
mveRichard MacCutchan25-Sep-11 23:12 
AnswerRe: Sample C# project Pin
BobJanova26-Sep-11 0:56
BobJanova26-Sep-11 0:56 
AnswerRe: Sample C# project Pin
uspatel26-Sep-11 1:52
professionaluspatel26-Sep-11 1:52 
GeneralRe: Sample C# project Pin
Software200726-Sep-11 17:41
Software200726-Sep-11 17:41 
QuestionMonitor a txt log file for keyword Pin
Tom Remmert25-Sep-11 9:20
Tom Remmert25-Sep-11 9:20 
AnswerRe: Monitor a txt log file for keyword Pin
Luc Pattyn25-Sep-11 9:59
sitebuilderLuc Pattyn25-Sep-11 9:59 
Hi,

1.
the cleanest approach would be to adapt the producer, which could not be acceptable or doable at all.

2.
the best approach on the consumer side depends on how (and how long) you want to run this. It could either be a utility that runs periodically, or an application that runs all the time and has a big delay (Thread.Sleep) or timer built in. If it is to run independent of a user being logged in, it better be a Windows Service.

3.
You need to remember how long the files were the last time you inspected them, and then only inspect whatever has been added to them. For a periodical utility this requires external storage (maybe an XML file), for a continuous app a mere Dictionary<string fileName, long fileLength> could do.

4.
You are currently reading the entire file; rather than using StreamReader.ReadToEnd, you could have used File.ReadAllText or File.ReadAllLines. However, if the observed app runs for hours or more, the log files could grow into the MB or GB, so that would not be practical. The latter two return the whole file, whereas the former returns anything from the current position to the end, so what you should do is use StreamReader.Position and StreamReader.ReadToEnd.

5.
BTW: there is no need for fs.Flush();, and this for two reasons: (a) the file is being read, not written, so there is no dirty data anywhere; and (b) it is followed right away by an fs.Close();, which always takes care of dirty data.

6.
There might be a slight chance that the things you are looking for get straddled over the "old" and the "new" log file (as in the log first ending on "Fai", then "led in some method" being appended); so it would be wise to back up a little when restoring the most recent position.

HTH

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: Monitor a txt log file for keyword Pin
Tom Remmert25-Sep-11 10:12
Tom Remmert25-Sep-11 10:12 
AnswerRe: Monitor a txt log file for keyword Pin
Luc Pattyn25-Sep-11 10:26
sitebuilderLuc Pattyn25-Sep-11 10:26 
GeneralRe: Monitor a txt log file for keyword Pin
BobJanova26-Sep-11 0:59
BobJanova26-Sep-11 0:59 
AnswerRe: Monitor a txt log file for keyword Pin
BillWoodruff25-Sep-11 10:36
professionalBillWoodruff25-Sep-11 10:36 
AnswerRe: Monitor a txt log file for keyword Pin
PIEBALDconsult25-Sep-11 16:49
mvePIEBALDconsult25-Sep-11 16:49 
QuestionWhat is the best way to create a dictionary apllication Pin
Yasser Sobhy25-Sep-11 4:12
Yasser Sobhy25-Sep-11 4:12 
AnswerRe: What is the best way to create a dictionary apllication Pin
PIEBALDconsult25-Sep-11 4:32
mvePIEBALDconsult25-Sep-11 4:32 
AnswerRe: What is the best way to create a dictionary apllication Pin
Muhammad Shahid Farooq25-Sep-11 4:39
professionalMuhammad Shahid Farooq25-Sep-11 4:39 
GeneralRe: What is the best way to create a dictionary apllication Pin
Richard MacCutchan25-Sep-11 5:26
mveRichard MacCutchan25-Sep-11 5:26 
GeneralRe: What is the best way to create a dictionary apllication Pin
Yasser Sobhy25-Sep-11 10:11
Yasser Sobhy25-Sep-11 10:11 
AnswerRe: What is the best way to create a dictionary apllication Pin
Richard MacCutchan25-Sep-11 6:07
mveRichard MacCutchan25-Sep-11 6:07 
GeneralRe: What is the best way to create a dictionary apllication Pin
Yasser Sobhy25-Sep-11 10:18
Yasser Sobhy25-Sep-11 10:18 
QuestionError 1001 : Unable to get installer types in my InstallHelper.dll assembly Pin
kutbinayi24-Sep-11 8:14
kutbinayi24-Sep-11 8:14 
AnswerRe: Error 1001 : Unable to get installer types in my InstallHelper.dll assembly Pin
Paramu197324-Sep-11 21:42
Paramu197324-Sep-11 21:42 
GeneralRe: Error 1001 : Unable to get installer types in my InstallHelper.dll assembly PinPopular
kutbinayi25-Sep-11 4:18
kutbinayi25-Sep-11 4:18 
GeneralRe: Error 1001 : Unable to get installer types in my InstallHelper.dll assembly Pin
shukla199019-Oct-23 3:57
shukla199019-Oct-23 3:57 
QuestionC# help please! Pin
Goran Shoan24-Sep-11 7:21
Goran Shoan24-Sep-11 7:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.