StreamWriter / Problems?

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?
 
J

Jon Skeet [C# MVP]

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?
 
J

Jon Skeet [C# MVP]

Leon said:
Nothing the ErrorLog does not get written anywhere?

Have you tried looking at what context.Server.MapPath returns in the
debugger?
 

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