views:

35

answers:

2

I have an ASP.NET MVC app hosted at webhost4life
What's a good way to save logs?
I have an access to the ftp I upload site to, should I just do effectively

 File.AppendAllText("log.txt", "Ooops, we have an error" + e.Message);

Or is there a better way? Send e-mail? save log into a database?

+2  A: 

I always try to log to a database and fall back on a file if the database is inaccessible (perhaps that's the cause of the exception). This allows you to run queries and reporting against the log directly and find out what the problem is immediately. You can also run a "health check" against the application by storing critical excepions and marking them, etc.

Joel Etherton
+1  A: 

Avoid writing to the file system; this can generate collisions/race conditions between threads that are attempting to write to the same file. Databases are wonderful solutions for this problem, and provide some nice benefits such as being able to generate reports easily from normalized data.

Also, what sort of information are you logging? The IIS logs are very detailed. Saving information that is already available in those logs duplicates work (the server writes its logs, and then you write your own), which of course incurs a performance hit.

David Lively
I'm hosting my web site on webhost4life.com I don't think I get an access to IIS log files.
Then stick with the database as Joel suggested; otherwise you face the possibility of file locking conflicts between threads. DB failure is rare enough that I don't worry about writing to a file as a backup, but that may not be the case with your application.
David Lively