VB.NET Service and StreamWriter - File In Use Error

K

Kevin

I'm writing a service in VB.NET. Reference the following code:

Dim oStreamWriter As StreamWriter
....
....
....
oStreamWriter = File.CreateText(TempLogFile)
If Err.Number <> 0 Then
EventLog.WriteEntry("LogService", "Error Creating Log File: " & _
TempLogFile & vbCrLf & _
"Error Code: " & Err.Number.ToString & vbCrLf & _
"Description: " & Err.Description.ToString, & _
EventLogEntryType.Error, 1004)
EventLog.WriteEntry("LogService", "Service Terminating", & _
EventLogEntryType.Error, 1004)
End
End If
oStreamWriter.WriteLine(buffer)
If Err.Number <> 0 Then
EventLog.WriteEntry("LogService", "Error Writing Log File Header
Row: " & _
ThisLogFile & vbCrLf & _
"Error Code: " & Err.Number.ToString & vbCrLf & _
"Description: " & Err.Description.ToString, & _
EventLogEntryType.Error, 1005)
EventLog.WriteEntry("LogService", "Service Terminating", & _
EventLogEntryType.Error, 1005)
End
End If
buffer = ""
--------------------------------------------------------------
Event Log Data Follows:
Event ID: 1004
Error Creating Log File: C:\WINNT\Temp\20040714_Security.log
Error Code: 57
Description: The process cannot access the file
"C:\WINNT\Temp\20040714_Security.log" because it is being used by
another process.
--------------------------------------------------------------

I've configured the Virus scanning to not scan C:\WINNT\Temp thinking
this was causing the issue, but was not. The Event ID traces to the
error check right after File.CreateText. The file does get create (0
byte file) in the folder specified. Service is configured to run as
an identity currently with Local Admin rights also. When testing on
Windows XP development box, works fine. Testing on W2K Server results
in the above error.

Using: MDE 2003 Version 7.1.3008
.NET Framework 1.1 Version 1.1.4322
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top