Luca, The EventLog.WriteEntry static method just creates a new instance of the EventLog object and sets the Source property. The EventLog Source should be the application name not the log name, it is displayed in the Source column in the Event Viewer application.
The issue that you have seen is caused because the .NET System.Diagnostics.EventLog methods SourceExists, LogNameFromSourceName, DeleteEventSource, and CreateEventSource just read and write the registry keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog. The EventLog service does not seem to re-read and update very frequently (or at all) based on the information in the registry. If you configure log4net to append to the EventLog and leave the LogName as the default (Application) then the EventLog service will remember that value even if you later change it in log4net. I'm not exactly sure what you need to do to recycle the EventLog service, it is not possible to restart it. It may even be necessary to restart the computer. Nicko > -----Original Message----- > From: Luca Priorelli [mailto:[EMAIL PROTECTED] > Sent: 04 October 2004 18:16 > To: [email protected] > Subject: EventLogAppender doesn't look right > > 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 > >
