Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logging errors, logins etc to a text file NOT the Event Log? 1

Status
Not open for further replies.

Seabrook7

Programmer
Jan 12, 2005
17
US
Hi everyone,

I'm trying to figure out the simplest way to keep a log file of the activity in our (VB)ASP.NET application. We'd like to log when users login or run a report or any errors they get.

I understand you can log to the Event Log with something like this:
Code:
 System.Diagnostics.EventLog.WriteEntry("Source", "Message")

But we'd like to write to a text file on the server instead. I've looked into using the TextWriterTraceListener class, but i'm not sure that that's neccessary.

I've also noticed a couple of .NET logging libraries like NLog and Log4Net. Are these neccessary?

Are any of you keeping text files for logs and how are you doing it?

Thanks!
Melissa
 
The thing is it all depends on what you want to log. The eventlog class will log windows events, although I think you can customize it. You can simple create a log file of your own on the server and write to it using the StreamWriter ojbect. Here is a good article on it, see part 2

I would personally create a table or tables to store the data. Although it requries writing to the db, it gives you the flexability to query and report off of the table if need be.

Jim
 
Thanks Jim!

That article is great. It's really easy to write to a file that way. Any idea if there would be access issues with this method.

As in, if more than one user's instance of the app is writing to the log at the same time? I'll look around to see if I can find any info on that. But if you have any let me know.

We thought about logging everything in our database, but the person that will be checking the logs has a few to look through every morning and we wanted to have them all in the same place. I know we could write a Stored Procedure to write out to the log every night or whenever, but we'd rather do it this way. Also, we think a lot of the errors that might come up would be database connection errors, so we don't want to rely on it to create the log files. Thanks for that tip though.

-Melissa
 
Well just another suggestion. If you do use a database table you could have a page in the app that pulls in the log to a datagrid for example for the person to look at. You could limit the rows by date for example. If all your apps log this way, you would only need one table, and not have this person going all over the place to check log files. Just my 2cents. If you do still decide to write the files, you could set up sql server to import the logs automatically into the table, then query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top