Adds some extra features to old-style (pre-.NET 2.0) diagnostics.
For a list of all members of this type, see StructuredTrace Members.
System.Object
StructuredTrace
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
This class leverages the powerful Trace facilities of .Net, adding a wrapper that conditionalizes the output. Additionally, the string that you pass to WriteLine is adorned with the thread name and the current date/time.
The Trace facility uses information in the system.diagnostics section of your app.config file. Here's an example showing 3 switches and a listener.
<system.diagnostics>
<switches>
<add name="main" value="0" />
<add name="thread" value="0" />
<add name="smarttip" value="0" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:/usr/tmp/mylog.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
A switch is accessed in your code with a statement like BooleanSwitch mainSwitch = new BooleanSwitch("main", "general tracing");
That mainSwitch can be passed to the StructuredTrace constructor to indicate whether you have enabled that setting in the config file or not. For those switches that you have enabled, Trace sends output to all of the defined listeners. There is a default listener named Default that sends output to the console. That is fine while inside Visual Studio where one has a console window even with a GUI application, but normally there will not be a console available, so you will observe that the Default listener is removed in the app.config section above. Since CleanCode 0.9.07.
Namespace: CleanCode.Diagnostics
Assembly: CleanCode (in CleanCode.dll)
StructuredTrace Members | CleanCode.Diagnostics Namespace