Writing to a log file with in an aspx file.

J

JuneCleaver

Hello,

I have been digging into writing into a file with the dot net
framework. There is a lot of information on it. I have a web
application and I want to write to a log file when an exception is
encountered. Writing to this file is not mission critical. Therefore
it seems like synchronous writing would be ok. I am looking for
something simple in what seems to be a complex topic. There are
fileinfos, streams, filesteams etc etc.

Does anyone have any advice on which of these objects to start with?
They all seem like overkill for what I want to do.

I want to create/open a file to a specific path like c:\logs\error.log
and write a variable of string class into it. I don't need to read
it.

Thanks,

HH
 
J

Juan Romero

My Dear friend,

You are having the same problem I had when I switched from VB to VB.NET.
It is not really overkill. It looks complex at first glance, but once you
get used to the new helper classes you will be fine.

What I suggest you do is:

1) Make yourself a small LogWriter Class that implements simple methods like
"WriteToLog", etc.

- OR -

2) Simply write the code to append a line to a certain file:

Dim w As StreamWriter = system.io.File.AppendText("logfile.txt")
w.WriteLine("Your hard drive is dying >:p ")
w.Flush() 'Update underlying file
w.Close()

Good Luck!
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top