Link to home
Create AccountLog in
Avatar of Priest04
Priest04Flag for Serbia

asked on

StreamWriter class - is it resource extensive?

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
ASKER CERTIFIED SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Priest04

ASKER

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?
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
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.