I am trying to read in a log file based on changes made to the file. I have a filesystemWatcher looking at the directory for changes, upon changes I run a procedure that checks if the log file was changed. If so I then read in the file, but it is locked because it's in use by another process. I need to queue it so it tries to read again when it's freed by the other application. I need to be efficient when reading the log file for specific keywords. I then need to pull the next few characters after the keywords are found. I am trying to do this so that it is quick enough to keep up with the program writing to the log file.
Here is what I got and it's failing.
Here is what I got and it's failing.
vbNET Code:
Public Sub StartInitialization() fLogWatch = New FileSystemWatcher With fLogWatch .BeginInit() .Path = _fLogPath .IncludeSubdirectories = False .EnableRaisingEvents = True .EndInit() _serviceStatus.currentState = Fix(State.SERVICE_RUNNING) SetServiceStatus(handle, _serviceStatus) End With AddHandler fLogWatch.Changed, New FileSystemEventHandler(AddressOf Log_Changed) End Sub Private Sub Log_Changed(ByVal obj As Object, ByVal e As FileSystemEventArgs) Dim strToFind As String = "CheckForAttachments Attachment Count:" Dim midStrToFind As Integer = 0 Dim resultStrToFind As String If e.FullPath = "C:\Users\xxxx\Documents\Sperry Software\SperrySoftwareLog.txt" Then For Each l In llist Console.WriteLine(l.ToString) Next End If 'Using readLog As New StreamReader(e.FullPath, System.Text.Encoding.Default, False, 4096) ' Dim input = readLog.ReadToEnd ' If input.Contains("CheckForAttachments Attachment Count:") Then ' resultStrToFind= Mid(strToFind,input. ' End If 'End Using End Sub