Trace.WriteLine() exceedingly slow

  • Thread starter Thread starter John Bailo
  • Start date Start date
J

John Bailo

I wrote a simple test program, console, that does one thing: log
DateTime.Now to a trace file.

I thought it would be lickety-split, but it's taking more than 10
minutes to write 1 million lines.

I looked at the trace and it's doing about 20 lines per second.

That's very slow.

I use Tracing a lot in my applications, and now I'm thinking its a big
overhead.
 
John said:
I wrote a simple test program, console, that does one thing: log
DateTime.Now to a trace file.

I thought it would be lickety-split, but it's taking more than 10
minutes to write 1 million lines.

I looked at the trace and it's doing about 20 lines per second.

That's very slow.

I use Tracing a lot in my applications, and now I'm thinking its a big
overhead.

You have many alternatives ... This are the first two that came to my mind.

One) is instead of writing each line store it in a StringBuilder (e.g.)
and when you have a reasonable amount of lines write it to the file
(This probably is faster than physically write line by line in the file)

Two) (My favorite) Use Enterprise Library Logging application block. It
is a framework specially designed for logging that can write to many
devices (file, sql server, event log ... )

Regards,
David Hernández Díez
MCDBA MCSD vs6 6 .NET
DCE5 .Net1.1 & DCE2 .NET 2.0
 
Back
Top