Click here to Skip to main content
15,914,481 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sample C# project Pin
PIEBALDconsult25-Sep-11 14:22
mvePIEBALDconsult25-Sep-11 14:22 
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 
Hello,
I have been digging on this topic for several days now, and cant seem to get started... Any advice is appreciated.

I have an application that outputs its log files to a txt file. I would like to write an app that can monitor that txt file for a keyword. Once that keyword is written to that log file, my app will send me an email notification.

If that keyword is appended to the log file, and I am successfully notified, I dont want the app to keep notifying me. Just one time per event.

I could do this in linux with tail -f, but am unsure how to complete this task in windows with C#...

I am currently using FileStream/StreamReader to search my text file for the keyword, and that works. But it keeps scanning the entire text file and keeps notifying me. I would just like it to read lines that are "new".

Thanks for any ideas... Would love to get started on this project...

Currently I am using this code found on codeproject forums:
<pre lang="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO; 
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Create a DirectoryInfo class and point it to the 
            // directory you want to search in
            DirectoryInfo dirInf = new DirectoryInfo(@"C:\Program Files\Temp");

            // Create a FileInfo array and get the file information 
            // of all the TXT files in the directory
            FileInfo[] files = dirInf.GetFiles("*.txt");

            // Loop though all the files found
            foreach (FileInfo currentFile in files)
            {
                // Create a files stream
                FileStream fs = new FileStream(currentFile.FullName, FileMode.Open);

                //create a stream reader
                StreamReader reader = new StreamReader(fs);

                //read the text in the file
                string fileContent = reader.ReadToEnd();

                if (fileContent.Contains("Failed"))
                {
                    MessageBox.Show("The File " + currentFile.FullName +
                                    " Contains the text your searching for");
                }

                // flush and close the IO objects
                fs.Flush();
                reader.Close();
                fs.Close();
            }
        }
    }
}


modified 25-Sep-11 15:34pm.

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 
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 

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.