I am currently using the following code to make sure a file is
writable (i.e. is not in use) by using the CanWrite method of the
FileStream object. Using the code below, the TextWriter is still
trying to write to the file and is throwing an exception (File... in
use by another process) whenever the output file (strFileName) is
open. I am trying to prevent it from writing to it at all if this is
the case... Any insight?
Public Shared Sub Log(ByVal logMessage As String)
Dim strFileName As New FileStream(strL ogFile, FileMode.Append ,
FileAccess.Writ e, FileShare.None)
If strFileName.Can Write Then
Dim w As StreamWriter = New StreamWriter(st rFileName)
w.WriteLine(Dat eTime.Now.ToSho rtDateString & vbTab &
DateTime.Now.To LongTimeString & vbTab & logMessage)
w.Flush()
w.Close()
End If
End Sub