G
Guest
Hi,
My very simple application VB.NET Visual Studio 2003 console application
uses a log file to write some text to it. I am using StreamWriter object to
create and open and then append text to the log file. Now what happens is
that if i have the folder in which the stream object creates the log file
open in windows explorer, i can see that it creates the log file but then it
crashes, strnage , can somebody tell me how i can stop this from happening.
Below is the function that does it. Seems it crashes at the line where i have
********. Also this error occurs only when the log file does not exit. Once
it has created the log file and the application is restarted, then there is
no problem even if the folder is open in windows explore.
thanks,
The error message is :
"System.IO.IOException: The process cannot access the file
"C:\projects\vb.net\saga\test\sagalog.txt" because it is being used by
another process."
The function code is :
Public Function WriteToLogfile(ByVal Text As String) As String
Dim logfile As StreamWriter
Dim Logfilepath As String =
ConfigurationSettings.AppSettings("LogFilePathandName")
Dim File As File
Try
If Not File.Exists(Logfilepath) Then File.Create(Logfilepath)
*************** logfile = New StreamWriter(Logfilepath, True)
'"SAGALogfile.txt")
logfile.WriteLine(Text)
logfile.Close()
Catch ex As Exception
Finally
'logfile.Close()
End Try
End Function
My very simple application VB.NET Visual Studio 2003 console application
uses a log file to write some text to it. I am using StreamWriter object to
create and open and then append text to the log file. Now what happens is
that if i have the folder in which the stream object creates the log file
open in windows explorer, i can see that it creates the log file but then it
crashes, strnage , can somebody tell me how i can stop this from happening.
Below is the function that does it. Seems it crashes at the line where i have
********. Also this error occurs only when the log file does not exit. Once
it has created the log file and the application is restarted, then there is
no problem even if the folder is open in windows explore.
thanks,
The error message is :
"System.IO.IOException: The process cannot access the file
"C:\projects\vb.net\saga\test\sagalog.txt" because it is being used by
another process."
The function code is :
Public Function WriteToLogfile(ByVal Text As String) As String
Dim logfile As StreamWriter
Dim Logfilepath As String =
ConfigurationSettings.AppSettings("LogFilePathandName")
Dim File As File
Try
If Not File.Exists(Logfilepath) Then File.Create(Logfilepath)
*************** logfile = New StreamWriter(Logfilepath, True)
'"SAGALogfile.txt")
logfile.WriteLine(Text)
logfile.Close()
Catch ex As Exception
Finally
'logfile.Close()
End Try
End Function