Writes a category name and the name of the value parameter to the trace listeners in the Listeners collection if a condition is true.
[Visual Basic] Overloads Public Shared Sub WriteIf( _ ByVal condition As Boolean, _ ByVal value As Object, _ ByVal category As String _ ) [C#] public static void WriteIf( bool condition, object value, string category ); [C++] public: static void WriteIf( bool condition, Object* value, String* category ); [JScript] public static function WriteIf( condition : Boolean, value : Object, category : String );
By default, the output is written to the managed code debuggers, the Microsoft.Win32.Interop.Windows.OutputDebugString API and to the Log method.
The category can be used to group output messages.
Notes to Implementers: You can minimize the performance penalty of instrumenting your application by using If...Then statements instead of using WriteIf statements. The following two code examples send the same debugging message. However, the first example is much faster when tracing is off, because if mySwitch.TraceError evaluates to false you do not call Write. The second example always calls WriteIf, even when mySwitch.TraceError is false and no tracing output is produced. This can result in unnecessary execution of an arbitrarily complex code.
First example.
if(mySwitch.TraceError) Trace.Write("aNumber = " + aNumber + " out of range");
Second example.
Trace.WriteIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");
Trace Class | Trace Members | System.Diagnostics Namespace | Trace.WriteIf Overload List | Debug | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute