Solved

StreamWriter class - is it resource extensive?

Posted on 2008-06-09
5
217 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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