Adds some extra features to old-style (pre-.NET 2.0) diagnostics.
System Object CleanCode.Diagnostics StructuredTraceNamespace: CleanCode.DiagnosticsAssembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
public class StructuredTrace
public class StructuredTrace
Public Class StructuredTrace
Public Class StructuredTrace
public ref class StructuredTrace
public ref class StructuredTrace
This class leverages the powerful Trace facilities
of .Net, adding a wrapper that conditionalizes the output.
Additionally, the string that you pass to WriteLine(String)
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>
<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>
BooleanSwitch mainSwitch = new BooleanSwitch("main", "general tracing");
BooleanSwitch mainSwitch = new BooleanSwitch("main", "general tracing");
A switch is accessed in your code with a statement like
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.