1

Okay so I have a WCF service writing to the Event Log.

All is well except for one detail..it won't pay any attention to the logName attribute,..here's the config.

    <!--EventLog Appender-->
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
        <logName value="MyCustomLog"/>
        <applicationName value="MyCustomEventSource" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
        </layout>
    </appender>

..and the initialization code.

        //Create an instance of the log from the declaring type.
        var stackTrace = new StackTrace();
        var frame = stackTrace.GetFrame(0);
        log = LogManager.GetLogger(frame.GetMethod().DeclaringType);
        BasicConfigurator.Configure();

The event log does get written to but in the Application log (using the MyCustomEventSource" source) rather than my own. Clearly I'm missing some important point but I don't see what that might be... I'm running on Win 7 and IIS 7.5 if that makes any diff.

Any help would be appreciated.

EightyOne Unite
  • 11,665
  • 14
  • 79
  • 105

1 Answers1

1

Did you create an event source?

I am surprised that your code works: You need to use the XmlConfigurator. As far as I know the BasicConfigurator only configures a default console logger...

Maybe also consider to create the loggers like this (seems cleaner and shorter):

ILog log = LogManager.GetLogger(typeof(YourClass));
Community
  • 1
  • 1
Stefan Egli
  • 17,398
  • 3
  • 54
  • 75
  • I forgot to mention that I was using the AssemblyInfo attribute using an XMLConfigurator. I marked you as correct since you pushed me in the right direction but my actual problem was that I had the event source registered to 2 separate logs. It was only logging to the most recent. – EightyOne Unite Aug 31 '10 at 12:09