3

I have an application that uses Trace.WriteLine in nearly every method it uses. The program has several different problems.

What I am wondering is if there is any overhead that comes with using System.Diagnostics.Trace.WriteLine so often? I am looking to solve problems as I discover them and I personally feel using Debug/Trace WriteLine in nearly every single method within the program has to come with a performance cost.

The programmer who wrote this application was rushed and also included some asset statements that has caused trouble for us in the past.

Security Hound
  • 2,577
  • 3
  • 25
  • 42
  • 1
    Did you profile the application? – Oded Apr 25 '11 at 15:30
  • Not a direct answer: Have you considered using something like Log4Net? This gives you the ability to dynamically turn up logging when needed. – Mitch Wheat Apr 25 '11 at 15:31
  • Mitch - There really is not a reason to even log what is going on within these methods. The programmer in question was behind and simply didn't know of a better method to trace the program's interaction with a third-party application. So the solution is simply to find out if the code itself leads to some performance lost. I really never used System.Diagnostics which lead me to simply asking what sort of possible performance problems it could lead to. – Security Hound Apr 25 '11 at 15:43
  • @Oded - I am not profiled the application. I wanted to get some thoughts on the subject before I suggested doing exactly that. I basically confirmed what I thought, the Trace statements could lead to a performance problem, and beyond the fact there is not logical reason every single method needs one its just ugly code. I need a better reason then "its ugly code" in order to remove said ugly code. – Security Hound Apr 25 '11 at 15:51

1 Answers1

6

It's possible that Trace could result in a performance problem for your application. Especially if it's used in every single method in the the program.

Luckily Trace.WriteLine has a Conditional attribute attached to it: Trace. If you compile the application without Trace defined it will compile as if the calls simply didn't exist. This will allow you to quickly do an eyeball test to see if it is affecting performance.

The only way to know though is to hook the application up to a profiler. This will tell you definitively if Trace.WriteLine is a problem for your application.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • This answers my question. The programmer who was tasked to design this program simply didn't know of another method to trace program's flow. – Security Hound Apr 25 '11 at 15:45