The Trace.WriteLineIf Method from the
System.Diagnostic.Trace facility writes a trace if
the condition passed as the first parameter is true.
TraceSwitch allows trace control via
bool properties for each relevant TraceLevel, such as TraceSwitch.TraceError.
Using Trace.WriteLineIf with such properties should be avoided since it can lead to misinterpretation and produce confusion.
In particular, Trace.WriteLineIf may appear as equivalent to the level-specific tracing methods provided by Trace, such
as Trace.Error, but it is not.
The difference is that Trace.WriteLineIf(switch.TraceError, …) conditionally writes the trace, based on the switch, whereas
Trace.TraceError always writes the trace, no matter whether switch.TraceError is true or
false.
Moreover, unlike Trace.TraceError, Trace.WriteLineIf(switch.TraceError, …) would behave like
Trace.WriteLine(…) when switch.TraceError is true, writing unfiltered to the underlying trace listeners and
not categorizing the log entry by level, as described more in detail in S6670.