Solved

StreamWriter class - is it resource extensive?

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now