This code creates and writes to the appropriate custom event log area when I'm 
logged on as an Administrator on a Windows XP box stepping through a 
ConsoleApplication project in VS2008:

class Program
{
    private static EventLogAppender _eventLogAppender;

    static void Main(string[] args)
    {
        LogLog.InternalDebugging = true;
        LogLog.EmitInternalMessages = true;

        ConfigureEventLogAppender("ApplicationName", "LogName");

        ILog log = LogManager.GetLogger(typeof(Program));

        // first entry: normal case
        log.Debug("Hello World");

        // second entry: also write an EventID
        var loggingEvent = new LoggingEvent(
            typeof(Program), 
            log.Logger.Repository, 
            log.Logger.Name, 
            Level.Debug, 
            "Hello World With EventId", 
            null);
        loggingEvent .Properties["EventID"] = 42;
        log.Logger.Log(loggingEvent );
    }

    public static void ConfigureEventLogAppender(string appName, string logName)
    {
        _eventLogAppender = new EventLogAppender();
        _eventLogAppender.ApplicationName = appName;
        _eventLogAppender.Layout = new SimpleLayout();
        _eventLogAppender.LogName = logName;
        _eventLogAppender.Threshold = Level.All;
        _eventLogAppender.ActivateOptions();
        BasicConfigurator.Configure(_eventLogAppender);
    }
}

Note the casing of "EventID" and that its being attached to LoggingEvent's 
Properties bag and not to the more general ThreadContext.



----- Original Message ----
From: James Green <[email protected]>
To: Log4NET User <[email protected]>
Sent: Friday, June 19, 2009 10:24:14 AM
Subject: EventLog Fun Continued.

Hi All,

I'm still at a total loss as to how to get log4net successfully writing
to a custom event log, writing to the Application event log is working
exactly as expected.

I have started using the IEventIDLog extension in order to pass over
event IDs to the log messages to see if this makes any difference.

I've looked over google a lot over the last couple of days and have
tried everything I have found in terms of suggestions.  The most recent
one being this:

http://www.mail-archive.com/[email protected]/msg02396.htm
l

Which talks of the same error I'm seeing in the application log that I
mentioned before:

I try to write to MyLog and this is entered into the Application log:

The description for Event ID ( 0 ) in Source ( MyFirstApp ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. You may be able to use the /AUXSOURCE= flag to retrieve this
description; see Help and Support for details. The following information
is part of the event: 2009-06-19 12:11:27,234 14 INFO <MachineName>
<username> Logging.TestHarness.vshost.exe (line: 220)
Logging.TestHarness.LogEntryCreator - Message number 71
System.Exception

I think tried this suggestion:

            ILog logger = LogManager.GetLogger(sender);
            log4net.ThreadContext.Properties["EventID"] = 12;
            logger.Info(0,message);

Which didn't make any difference.  I have checked over the Sources key
entries being created in the registery and all seems to be correct in
there as well.  I just never see *anything* making it into the MyLog
event log.

I've probably got another 2 hours left to use on this before I have to
move onto other work which is incredibly frustrating as I will leave
behind a 'buggy' half finished wrapper.

Any input would be much appreciated.

:|

James

Reply via email to