Click here to Skip to main content
15,902,938 members
Home / Discussions / C#
   

C#

 
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 
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 
Here's an idea:

1. in your monitoring class keep a class-instance-scoped (or static ?) variable that maintains the index in the log file where the last instance of 'failed' was seen.
public int lastFailIndex;
2. on notification:

a. read in the file, as you do now

1. get the index of the last instance of the string 'failed'
int currentFailIndex = fileContent.LastIndexOf("failed");
2. compare to stored Index
if(currentFailIndex > lastFailIndex)
{
   // new fail: take care of business
   lastFailIndex = currentFailIndex;
}


2. another simple remedy to see if the file has changed at all would be to store the length of the string created by ReadToEnd, and compare each time to see if the file has become larger: of course, you may know the log file, inherently, will be larger each time you open it, in which case: forget about that.
But, it's more interesting to think a little "out of the box" here:

1. if your log-file is delineated by lines (carriage returns and/or linefeeds) you could use File.ReadAllLine(/filepath/) to return an array of strings, and then work backwards from the end of that array to see if you have a new instance of a "failed."

In this case the 'Count property of the string array could be preserved to test for file change ?

For discussions on other (more elaborate) techniques to read a file from the end, and even a code example from Master Jon Skeet himself, check out[^].

best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"

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 
AnswerRe: C# help please! Pin
Luc Pattyn24-Sep-11 7:30
sitebuilderLuc Pattyn24-Sep-11 7:30 
GeneralRe: C# help please! Pin
Goran Shoan24-Sep-11 7:43
Goran Shoan24-Sep-11 7:43 
GeneralRe: C# help please! Pin
AnnieMacD26-Sep-11 1:52
AnnieMacD26-Sep-11 1:52 
AnswerRe: C# help please! Pin
André Kraak24-Sep-11 7:40
André Kraak24-Sep-11 7:40 

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.