1

I write a lot of logs every day (millions of strings per day, up to 1 Gb of logs). I'm interested if when I set AutoFlush I significantly slow-down computer or "damaging" HDD (SaS 15000 if this is important)? Will HDD do some expensive extra operations every time new line is wrote (like opening file, modifing closing etc. etc.)

Well likely I just should not use AutoFlush but sometimes I want to use it to troubleshoot other problems.

Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305

1 Answers1

3

I'm not sure who down voted your question or why (but I can guess).

According to http://msdn.microsoft.com/en-us/library/system.io.streamwriter.autoflush.aspx, using AutoFlush will definitely slow down your code. You need to do some testing to determine how much it'll slow down, and whether getting the log messages is worth the cost.

If I were you I'd seriously review the logging - do you really need that much data, every day? My guess is that your program's performance will increase dramatically if you can eliminate most if not all of it.

If for whatever reason you cannot eliminate the logging, then take a look at some logging libraries like log4net or Enterprise Logging. See How to do logging in c#? for more info. Those libraries have been written and thoroughly performance tested by people with way too much time on their hands; the library is less likely to contain errors or bottlenecks than home-grown code.

Community
  • 1
  • 1
Dan Pichelman
  • 2,312
  • 2
  • 31
  • 42