34

Anyone knows the difference between System.Diagnostic.Trace and System.Diagnostic.TraceSource classes?

I've been using Trace for most of my projects and I just happen to found out about TraceSource the other day. They seems to offer similar API, is one better than the other?

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
oscarkuo
  • 10,431
  • 6
  • 49
  • 62

2 Answers2

32

TraceSource is the newer version (since .NET 2) and Trace is the older version, more info is available here:

Clarification on TraceSource/Trace

Steve Temple
  • 2,238
  • 19
  • 27
  • 4
    From http://msdn.microsoft.com/en-us/library/ms228989.aspx: "TraceSource is intended to function as an enhanced tracing system and can be used in place of the static methods of the older Trace and Debug tracing classes. The familiar Trace and Debug classes still exist, but the recommended practice is to use the TraceSource class for tracing." – sourcenouveau May 11 '10 at 15:53
  • This article could be very helpful too. http://blogs.msdn.com/b/bclteam/archive/2005/03/15/396431.aspx – Hakan Fıstık Sep 02 '15 at 12:27
10

TraceSource allows you to enhance the granularity over your tracing : in your config file you can enable/disable only the tracesource you want at the level you want (information, warning, error, ...) You can find really good explanation here : http://www.codeproject.com/Articles/149251/Debugging-Tracing-and-Instrumentation-in-NET-and-A

Sylv21
  • 345
  • 2
  • 11