We have a Log class which write log entries into a log file via StreamWriter. Each time when its logItem() is called, an entry will be passed in and write to the file. Right now after the WriteLine() method call, a Flush() is also called.
Do you think it is necessary to call Flush() for each write? any performance impact?
EDIT:
This is for very old versions of .net framework. see the comments
It will reduce performance a lot.
It is always better to use AutoFlush, because it is optimized and fast, and doesn’t need a lot of code to do the job.
if you are not going to use autoflush, flushing every 50 or 60 lines will give you better performance, but the number depends on line lengths(usually 4KB is OK for every flush)
a better way is using a binary protocol and use some code to read it, it is always faster with no condition.