StructuredTrace ClassCleanCode C# Libraries v1.2.03 API
Adds some extra features to old-style (pre-.NET 2.0) diagnostics.
Inheritance Hierarchy

OnlineSystem Object
  CleanCode.Diagnostics StructuredTrace

Namespace: CleanCode.Diagnostics
Assembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
Syntax

public class StructuredTrace
Remarks

This class leverages the powerful OnlineTrace 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>
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.

See Also