Writing to a log file with in an aspx file.

  • Thread starter Thread starter JuneCleaver
  • Start date Start date
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
 
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!
 
Back
Top