Support > Samples > Style Sheet Publisher

Style Sheet Publisher

Download source code


This sample application demonstrates how to trace messages into a simple text file formated with a Cascading Style Sheet file.

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 into a text file and format the message.

<?xml version="1.0" encoding="utf-8" ?>
                Css.Diagnostics.TraceComLib" />
    <traceManagement mode="On">
        TraceStylesheetPublisher applies the style sheet for each message 
        before writing it to a text file.
        filename:   Name of the trace file to write the formatted message to.
        stylesheet: Name of the xslt stylesheet to use for formatting the trace message.
            <publisher key="TraceStylesheetPublisher1" 
                   <attribute name="filename" value="..\..\MyTraceFile.txt"/>
                   <attribute name="stylesheet" value="..\..\FormatTraceMessage.xslt" />
                    <filter type="*" level="4" />
            <filter type="*" level="4"></filter>
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.


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

namespace Css.Coyote.Samples.StyleSheetPublisher
    class Program
        static void Main(string[] args)
                    , AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
                    , true);

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

                throw ex;
            catch (Exception)
                TraceAgent.Write(ex, TraceLevel.Error);

            Console.WriteLine("Look in the MyTraceFile.txt!");
Step 4: Open Trace File

After tracing with the above configuration the trace message appears in the text file.