Reputation: 361
I have been writing an app in vb.net to copy the last few lines of an IIS W3C log file every few minusts to A file that will be used for some remote reporting.
The Code:
Dim linex = ""
Dim Line = ""
'### IT ERROS OUT ON THE NEXT LINE ###
Using sr As New StreamReader("C:\inetpub\logs\LogFiles\W3SVC14\u_ex130702.log")
Do Until sr.EndOfStream
linex = sr.ReadLine()
line = line & linex & vbCrLf
Loop
End Using
Upvotes: 1
Views: 411
Reputation: 100547
You need to specify correct sharing options and open mode when creating underlying FileStream
. Since there is no constructor of StreamReader
that passes all necessary arguments you need to construct FileStream
first using FileStream(String, FileMode, FileAccess, FileShare) and than create StreamReader
on it using SrteamReader(Stream).
I think following should open IIS log file while it is being written to by IIS (if not - try other combinations of flags)
Using stream As New New FileStream( _
"Test#@@#.dat", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Using sr As New StreamReader(stream)
Upvotes: 1