473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Log files and cans of worms

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.

Jan 9 '06 #1
2 848
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.

"pi**********@hotmail.com" wrote:
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.

Jan 9 '06 #2
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.

"Bruno van Dooren" wrote:
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.

"pi**********@hotmail.com" wrote:
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.

Jan 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill | last post by:
I'm creating a company intranet, and every employee has certain program we want them to be able to run from it, meaning we want the link to the program to be on the intranet page. For example,...
2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
19
by: Chris | last post by:
Hello all A new standards based and CSS designed site I recently completed is soon to go live. After much testing and tweaking I have fianlly managed to get the site to look as it should on...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
18
by: Michael | last post by:
Hi, I moved to c++ from c, and wanted to know what the best way to read data from files is in c++. Any thoughts? fscanf() is possible but fairly painful! Regards Michael
3
by: Stuart Konen | last post by:
Hi, I recently contacted a Microsoft service rep and was directed here. My problem is getting worse and worse. Here is the original message (several days ago): I've been using your Microsoft...
5
by: Firecore | last post by:
Hi. My brother is an expert at C & C++ He is always making small annoying programs similar to Worms and Viruses. I have learnt VB and some C. Anyone got any ideas as to how I can stop him short...
5
by: Salad | last post by:
As far as I'm concerned I support the chopping off of fingers of programmers that put out worms and viruses. I could care less if the programmer was 5 years old...off with the fingers. Anyway,...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.