Reputation: 31
I have a log file in Production server which keeps on getting updated by a program(very frequently. say 5 to 10 times per second.).
This log file obviously read-only to Dev server, and chances the file size go up to ~4MB.
I have a program in Dev environment. That periodically reads the file content and looks for a specific lines/keywords.
************************
If File.Exists(targetFile) Then
Using fs As FileStream = New FileStream(targetFile, FileMode.Open, FileAccess.Read)
Using sr As StreamReader = New StreamReader(fs)
Dim all As String = sr.ReadToEnd()
allLines = all.Split(Environment.NewLine)
End Using
End Using
End If
********************************
My problem is, it looks like that reading from dev server locking the file[not sure]. So the service is PRD not able to access the file and throwing errors.
Upvotes: 0
Views: 1242
Reputation: 45173
You are using this overload of the FileStream
constructor. The documentation says
The constructor is given read/write access to the file, and it is opened sharing Read access (that is, requests to open the file for writing by this or another process will fail until the FileStream object has been closed, but read attempts will succeed).
If you want to allow other processes to read and write to the file, you must open in FileShare.ReadWrite
mode, using this overload.
Upvotes: 4