开发者

Why is Log4Net ignoring my logName?

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 开发者_如何学JAVAlog 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.


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜