• XSLT note 1 - built-in template

    A simple xslt is a empty xslt.

  • TraceSource

    In my post How to control whether to output Trace, I discussed how to output behavior of Trace object. We can control destination with the system.diagnostics.trace section, and control the when to output Trace by using listener's filter or using switch.

  • How Trace works with Listner

    Listner control destination the output of Trace. Here is how.

  • How to contro whether output Trace

    We already know Listner affect Trace object's output destination. But that is only an aspect of behavior, another aspect is whether the message should be output. The control this we can test a configurable switch's value to determine whether we should output the message. But we need to manually Test the the switch, or we need to write a helper class to wrap the test code. Here is the code.

  • Trace.Assert

    In nunit or other test framework, we have Assert object to test whether result is as expected. If assert is false, then en exception is through. Trace.Assert is provide similar function, but for different purpose. It is for diagnostic. When assert is false, it output the error message to a listener. There is default listener in .net, which is DefaultTraceListener An instance of this class is automatically added to the Debug..::.Listeners and Trace..::.Listeners collections. Explicitly adding a second DefaultTraceListener causes the message also show in the debugger output window and the messageboxe for asserts. The DefaultTraceListner looks like throwing an exception, but it is not actually an exception, it is for user interaction and there is no exception to catch at all. If you remove the DefaultTraceListner like below, you will not see this output, and the execution will continue.

    <img style=”cursor:pointer; cursor:hand;width: 400px; height: 70px;” src=”http://1.bp.blogspot.com/_yUba7cqllFE/SUp5G3ixumI/AAAAAAAAAPw/LGnV259pTc4/s400/assertfail.PNG” border=”0” alt=”“id=”BLOGGER_PHOTO_ID_5281166671941319266” />

    <configuration>
      <system.diagnostics>
        <trace>
          <listeners>
            <clear/>
            <add name="text" />
          </listeners>
        </trace>
        <sharedListeners>
          <add name="text" type="System.Diagnostics.TextWriterTraceListener" initializeData="textfileListner.log" />
        </sharedListeners>
      </system.diagnostics>
    </configuration>