Log files and cans of worms

  • Thread starter Thread starter pigeonrandle
  • Start date Start date
P

pigeonrandle

Hi,
I'm quite sure this could start a lot of arguements :p.

If i am creating a log file that is constantly added to during the
lifetime of my program, is it best to have a permanent Streamwriter
object that i write to and then flush after each comment, or to spawn a
new one each time i need to add to the log? Or maybe there's some
magical medium i haven't heard of?

Forget the postcards, just post your answers here instead.

James.
 
if you constantly need to add data, opening and closing a stream will carry
overhead. flushing after you add data is a better idea, but you could also
flush when your program exits.
that way you won't interrupt your program to do file io.

or maybe you can use the windows event log. the advantage is that you get a
nice reporting tool for free: the windows event log viewer.
check out the System.Diagnostics.EventLog class. however, the event log is
meant for logging important application events or failures. if you want to
capture tons of debug data it is not appropriate..

or if you want to log data during or after a measurement of something, you
could also stream your data to a database e.g. SqlServer. that way, you could
use things like crystal reports for generating result reports.

or if you want to keep track of internal data flow in you program (nr of
actions per second etc) you could implement a performance counter that can be
watched with the performance viewer.

it really depends on what you want to do with the data.

kind regards,
Bruno.
 
Forgot to add:
if the logged data is for debugging or tracing purposes, you can also use
the Trace class and Debug class from the System.Diagnostics namespace.

these are excellent tools with which you can specify the trace level via the
application ini file.

kind regards,
Bruno.
 
Back
Top