为什么 Log4Net 忽略我的 logName?

发布于 2024-09-15 22:34:03 字数 1000 浏览 2 评论 0原文

好的,我有一个 WCF 服务写入事件日志。

除了一个细节之外,一切都很好..它不会关注 logName 属性,..这是配置。

    <!--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>

..和初始化代码。

        //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();

事件日志确实被写入,但在应用程序日志中(使用 MyCustomEventSource“源)而不是我自己的日志。显然,我错过了一些重要的点,但我不知道那可能是什么......我正在运行Win 7 和 IIS 7.5 如果有任何差异,

我们将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提赋 2024-09-22 22:34:03

您是否创建了事件源

我很惊讶您的代码可以工作:您需要使用 XmlConfigurator。据我所知,BasicConfigurator 仅配置默认控制台记录器...

也许还可以考虑创建这样的记录器(看起来更干净、更短):

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

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文