Saturday, February 04, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: EventLog Fun Continued.
Prev Next
You are not authorized to post a reply.

Author Messages
James Green

06/19/2009 4:24 PM  

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/log4net-user@logging.apache.org/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

Ron Grabowski

06/19/2009 11:21 PM  


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.

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > EventLog Fun Continued.



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement