Difference between using Trace and TraceSource

2019-04-03 07:09发布

问题:

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?

回答1:

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

Clarification on TraceSource/Trace



回答2:

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