views:

54

answers:

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.

+1  A: 

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));
Stefan Egli
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.
Stimul8d