Support > Samples > Coyote as TraceListener

Coyote as TraceListener

Download source code

 

This sample application demonstrates how to trace messages with the Coyote Core Framework with adapting the source code of an existing application.

Step 1:  Configure your application

To enable tracing in your application it's important to add the “traceManagement” section into your application configuration file. The following sample shows the necessary configuration to trace messages from Debug.Write().

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section
            name="traceManagement"
            type="Css.Diagnostics.TraceManagementSection, 
                Css.Diagnostics.TraceComLib" />
  </configSections>
  <traceManagement mode="On">
    <publishers>
      <publisher key="TraceSvrPublisher1" mode="On" 
                 assembly="Css.Diagnostics.TraceComLib" 
                 type="Css.Diagnostics.Publishers.TraceSvrPublisher">
        <attributes>
          <attribute name="url" 
                     value="tcp://localhost:13400/TraceSvr.rem" />
        </attributes>
        <filters>
          <filter type="*" level="4"></filter>
        </filters>
      </publisher>
    </publishers>
    <filters>
      <filter type="*" level="4"></filter>
    </filters>
  </traceManagement>
    <system.diagnostics>
        <trace autoflush="true" indentsize="2">
            <listeners>
                <remove name="Default"/>
                <add name="TraceAgentTraceListener"
                 type="Css.Diagnostics.TraceAgentTraceListener,
Css.Diagnostics.TraceComLib"
/> </listeners> </trace> </system.diagnostics> </configuration>
Step 2: Reference Css.Diagnostics.TraceComLib

The whole tracing technology is located in the “Css.Diagnostics.TraceComLib” Library. Referencing this Library in your application offers you the possibility to create and trace messages.

Step 3: Tracing

The following snippet shows a possible implementation to trace messages in your application by using the usual System.Diagnostics.Debug.Write() method.

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.Remoting;

namespace Css.Coyote.Samples.TraceListener
{
    class Program
    {
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure
                (System.IO.Path.Combine(
                      AppDomain.CurrentDomain.BaseDirectory
                    , AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
                    , true);

            Exception ex = new Exception("If you read this, everything works fine ;-)");

            try
            {
                throw ex;
            }
            catch (Exception)
            {
                Debug.Write(ex, "Exception");
            }

            Console.WriteLine("Look at your Coyote Trace Monitor!");
            Console.ReadKey();
        }
    }
}
Step4: Start Coyote Trace Monitor
Click: File - New - Run 
Step5: Start your application

Your Coyote Trace Monitor should display the exception you have traced: