One additional note is the concurrency may be hard to maintain when writing
to a file, unless each session has their own log file. Suppose two sessions
(users) encounter an error, and they both try to write to the file at the
same time. Two things can happen, 1) The first one to open the file will
also lock it, but then the second access attempt will error because the file
is locked, or 2) Both will try to write to the file at the same time and
the log entries will become mangled.
There are ways to mitigate this, but just wanted to point out the issues so
that you can design something appropriate. Another alternative might be to
log to the event log.
"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op***************@cowboy.hsd1.mn.comcast.net. ..
On Sun, 17 Apr 2005 10:20:00 -0500, Plop Plop via DotNetMonster.com
<fo***@nospam.DotNetMonster.com> wrote:
Hello,
i'm a newbie at asp.net, and i'm developping a site at the moment, and
want
to add a sort off logging system.
I would like to create a file on the server side when a error occured.
Now how can i do that?
On my pc i have c:\inetput\wwwroot\sitename
i want the file to become in this directory, but i can't use this path
because when i upload it to a host server, the path will be different.
So
how can i make sure the file comes in the directory where my site is
located without statically typing in the path in a string orso?
Or thus someone has a better idea of solving this problem?
thank you
Check out HttpServerUtility.MapPath method, takes a virtual path on the
server and maps to an actual server path:
http://msdn.microsoft.com/library/de...ppathtopic.asp
Note a reference to HttpServerUtility is available thru the Server
property of your Page; i.e. to use this inside one of your pages:
//to create file in same dir as page
Server.MapPath("myFile.txt")
//to create file in parent directory
Server.MapPath("../myFile.txt")
etc
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET