Support > Samples > Event Log Publisher

Event Log Publisher

Download source code


This sample application demonstrates how to trace messages into the Windows Application Event Log.

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 the Windows Application Event Log.


<?xml version="1.0" encoding="utf-8" ?>
                Css.Diagnostics.TraceComLib" />
    <traceManagement mode="On">
            TraceEventLogPublisher allways writes to the trace messages to the 
            application event log log.
            source: written to the eventlog as source of the event log event.
            <publisher key="EventLogPublisher1"  mode="On" 
                    <attribute name="source" value="TraceAgentTester"/>
                    <filter type="*" level="1" />
            <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.EventLogPublisher
    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 at your EventLog!");


Step 4: Open Windows Application Event Log

After tracing with the above configuration the trace message appears in the Event Log.