I have an application in which I want to write entries to the event log. The logger is launched via MEF. I created a derived class to be able to initialize the log before using it.
My code is as follows:
public class WinEventLog : EventLog, ILogger { private const string LOG_SourceName = "DataGen_Source"; private const string LOG_SysLogName = "Pool_Log"; private bool _isInitialized = false; public WinEventLog() : base() { Initialize(); } public void LogMessage(MessageLevel level, string message) { WriteEntry(message, level.EventLogType()); } public void LogMessage(string source, MessageLevel level, string message) { WriteEntry(source, message, level.EventLogType()); } public void Initialize() { if (!_isInitialized) { this.BeginInit(); this.EndInit(); if (!System.Diagnostics.EventLog.SourceExists(LOG_SourceName)) { System.Diagnostics.EventLog.CreateEventSource( LOG_SourceName, LOG_SysLogName); } Source = LOG_SourceName; Log = LOG_SysLogName; _isInitialized = true; } } }
However, the registrar does not write to the log that I specify, Pool_Log, but in the application log.
Any idea why this is happening?
EDIT
I mentioned EXACT the same component from another project, and in this situation he wrote the correct EventLog !!!
I am puzzled!
thanks
source share