Priest04
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
http://www.codeproject.com/KB/cs/simpleeventlog.aspx
This is a better implementation:
http://www.codeproject.com/KB/cs/eventlogex.aspx
ASKER
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.
ASKER
Jaime, can you point me to some resource/example how would I reuse windows event feature?