Solved

StreamWriter class - is it resource extensive?

Posted on 2008-06-09
5
228 Views
Last Modified: 2013-11-07
I need to make some sort of an EventViewer class, which will append some events in a file. and when necessary display the events to user. There could be up to 300 events per day, but usually its around 100 events per day. What approach should I take in this situation? This is what I am thinking at the moment:

1) I could make EventViewer class declared as static, and have StreamWriter (used by EventViewer internally) open the file, and keep it open for the application lifetime.
2) I could make EventViewer class declared as static, and have StreamWriter (used by EventViewer internally) open the file whenever it needs to write an event, and close it after it is done


Which one would you choose, performance wise, or if you have some better opinion, I would be glad to hear it.

Thanks,
Goran
0
Comment
Question by:Priest04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 250 total points
ID: 21745833
use the number one to avoid open and close the StreamWriter every time.
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 250 total points
ID: 21745837
So, you are talking about an "EventWriter", not an EventViewer.
About keeping the file open during the application lifetime. There is a imperceptible difference against open/close the file, since there is a small amount of transactions. I think you can keep it open for simplicity.
As a side comment, I suggest you to use the Windows Event feature instead of implementing your own, so you can use the Windows Event Viewer tool to look for them. Also this will give your application a touch of professional-looking.
 
0
 
LVL 18

Author Comment

by:Priest04
ID: 21746149
Thanks for the comment, it would be my final choice, too.

Jaime, can you point me to some resource/example how would I reuse windows event feature?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21746211
here is a basic implementation example:
http://www.codeproject.com/KB/cs/simpleeventlog.aspx
This is a better implementation:
http://www.codeproject.com/KB/cs/eventlogex.aspx
0
 
LVL 18

Author Comment

by:Priest04
ID: 21746936
I would need to log events for every day for whole year. Whole logs needs to be available until the end of the year, and then they can be deleted (archived). Would you find your approach suitable for this task? I didn't have time to go thoroughly trough the articles you have provided, only dropped a quick view on the EventLog class.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question