Event log trace listener to log messages to custom event source RRS feed

  • Question

  • I've got an EventLogTraceListener set up in my code and currently configured to write to the default Windows event log, in this case the Application log.  I've created a new event log source and I want to be able to write my messages to the new event log source and not the default (application log).  I've seen a couple of examples that pass the log name into the initializedata attribute of the tracelistener, but I'm not able to get this to work.  Any help would be greatly appreciated.  Here is a snippet from my app.config:

          <source name="RoutingServiceSource" switchName="RoutingServiceSourceSwitch" switchType="System.Diagnostics.SourceSwitch">
              <!--<add name="RoutingServiceListener" type="System.Diagnostics.EventLogTraceListener" initializeData="Log=AGOC;Source=AGOC.Routing.Outbound">-->
              <add name="RoutingServiceListener" type="System.Diagnostics.EventLogTraceListener" initializeData="RoutingService">
                <!--<filter type="System.Diagnostics.EventTypeFilter" initializeData="Error"/>-->
        <!--<trace autoflush="false" indentsize="4">
            <add name="RoutingServiceListener" type="System.Diagnostics.EventLogTraceListener" initializeData="RoutingService">
        <!--Switch values:
            Error=Output error-handling messages.
            Info=Output informational messages, warnings, and error-handling messages.
            Off=Output no tracing and debugging messages.
            Verbose=Output all debugging and tracing messages.
            Warning=Output warnings and error-handling messages.-->
          <add name="RoutingServiceSourceSwitch" value="Error" />

    Tuesday, December 10, 2013 3:56 PM


  • Hello Kenny,

    Writing to a different source can be tricky because there differences between operating systems (os server versions) and permissions.

    I am guessing but this could be because you need to create the application source explictly and associate RoutingServiceSource to the RoutingService eventlog.  Below is an example from MSDN and is performed at the startup of the service or program (note: from memory server 2003 did not require this but newer server versions do):

     // Create the source, if it does not already exist. 
                // An event log source should not be created and immediately used. 
                // There is a latency time to enable the source, it should be created 
                // prior to executing the application that uses the source. 
                // Execute this sample a second time to use the new source.
                EventLog.CreateEventSource("MySource", "MyNewLog");
                Console.WriteLine("Exiting, execute the application a second time to use the source.");
                // The source is created.  Exit the application to allow it to be registered. 
            // Create an EventLog instance and assign its source.
            EventLog myLog = new EventLog();
            myLog.Source = "MySource";
            // Write an informational entry to the event log.    
            myLog.WriteEntry("Writing to event log.");
            Console.WriteLine("Message written to event log.");  
    These might help:


    Tuesday, December 10, 2013 10:25 PM