I have tried to use the EventLogAppender using a log name (source) different from 'Application' which is the default.
The EventLogAppender insists to send the events to the 'Application' log file.
Microsoft documentation states that in order to write to a new Event Source it is not sufficient to invoke
'EventLog.CreateEventSource ()' but the Source property of the EventLog class must be set.
Since the EventLog property is not static it is not possible to call only static class members, as the EventLogAppender does.


I have made the following changes to the code, and now it works:

      // ============= ADDED
*        private EventLog m_eventLog;
*         // ===========================

public EventLogAppender()
{
m_applicationName = System.Threading.Thread.GetDomain().FriendlyName;
m_logName = "Application"; // Defaults to application log
m_machineName = "."; // Only log on the local machine


           // ============= ADDED
*            m_eventLog            = new EventLog ();*
           // ===========================
      }

      override public void ActivateOptions()
      {
           // ... stuff deleted

           // ============= ADDED
*            m_eventLog.Source = LogName;*
           // ===================

LogLog.Debug("EventLogAppender: Source [" + m_applicationName + "] is registered to log [" + EventLog.LogNameFromSourceName(m_applicationName, m_machineName) + "]"); }


// ============= CHANGED
//EventLog.WriteEntry (m_applicationName, eventTxt, GetEntryType(loggingEvent.Level), eventID);
* m_eventLog.WriteEntry (eventTxt, GetEntryType(loggingEvent.Level), eventID);
* // ===================


Luca



Reply via email to