I am trying to write to a text file while protecting it from concurrent access. What is the advantage of fileStream.lock ? (when I created a filestream in the code below, the file seemed to be protected from other processes using it).
I am not sure if I need to use filestream.lock below. Please advise ..
Public Shared Sub writeToLogFile(ByVal logMessage As String)
Dim strLogMessage As String = String.Empty
Dim strLogFile As String = System.Web.HttpContext.Current.Server.MapPath("~/Log.txt")
Dim swLog As StreamWriter
strLogMessage = DateTime.Now.ToLongTimeString().ToString() & " ==> " & logMessage
Dim fileStream As New FileStream(strLogFile, FileMode.Append)
' Lock all of the file after creating the filestream object
View Complete Post