StreamWriter / Problems?

  • Thread starter Thread starter Leon
  • Start date Start date
L

Leon

I wrote an custom error handler that works, but why the ErrorLog.txt file is
being created/written in the root web instead of the folder within my web
application?
Root web = C:\Inetpub\wwwroot -&- Web Application Folder =
C:\Inetpub\wwwroot\MySite
See code:
Public Shared Sub LogError(ByVal message As String)
' Get the current HTTPContext
Dim context As HttpContext = HttpContext.Current
' Get location of ErrorLogFile from Web.config file
Dim filePath As String = context.Server.MapPath( "../../ErrorLog.txt")
' Write message to error file

Try
Dim sw As New System.IO.StreamWriter(filePath, True)
sw.WriteLine(message)
sw.WriteLine()
sw.Close()

Catch
' If error writing to file, simply continue
End Try

End Sub
End Class
End Namespace
and if I try to hard code write the error to my ErrorLog text file it in my
web application (such as "MySite/ErrorLog.txt") nothing gets written?
 
Leon said:
I wrote an custom error handler that works, but why the ErrorLog.txt file is
being created/written in the root web instead of the folder within my web
application?

Well, you're asking for two directories above the web site - what
happens if you use context.Server.MapPath ("ErrorLog.txt") instead?
 
Back
Top