log4net 不使用 .net 1.1 和 .net 3.5 的混合进行日志记录

发布于 2024-08-25 16:35:11 字数 1996 浏览 4 评论 0原文

我在 Windows 2003 生产计算机上有一个 iis 服务器,它不会在 .net3.5 Web 应用程序中使用 log4net 进行日志记录。 Log4net 在使用 log4net 版本 1.2.9.0 的 1.1 应用程序中工作正常,但在 3.5 Web 应用程序中则不然。日志记录在开发和登台环境中工作正常,但在生产环境中则不然。它没有错误,我没有收到事件查看器中记录的事件,并且不知道下一步该看哪里。我尝试过 log4net 的两个版本(1.2.9.0 和 1.2.10.0),并且都可以在开发和登台中工作,但不能在生产中工作。

出于测试目的,我仅创建了一个单页面应用程序,它仅回显页面被点击的时间,并且还应该使用 log4net 记录到我的日志文件中。

这是我的 web.config 文件:

    <configSections>
    <!-- LOG4NET Configuration -->
    <section name="log4net"  type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" requirePermission="false" />
</configSections>

<log4net debug="true">
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="D:\DIF\Logs\TestApp\TestApp_"/>
        <param name="AppendToFile" value="true"/>
        <param name="RollingStyle" value="Date"/>
        <param name="DatePattern" value="yyyyMMdd\.\l\o\g"/>
        <param name="StaticLogFileName" value="false"/>
        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%date{HH:mm:ss} %C::%M [%-5level] - %message%newline"/>
        </layout>
    </appender>
    <root>
        <level value="ALL"/>
        <appender-ref ref="RollingFileAppender"/>
    </root>
</log4net>

这是我的 log4net 初始化:

        // Logging for the application
    private static ILog mlog = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    protected void Application_Start(object sender, EventArgs e)
    {
        try
        {
            // Start the configuration of the Logging
            XmlConfigurator.Configure();

            mlog.Info("Started logging for the TestApp Application.");
        }
        catch (Exception ex)
        {
            throw;
        }
    }

任何帮助将不胜感激。

谢谢,

吉姆

I have an iis server on a windows 2003 production machine that will not log using log4net in the .net3.5 web application. Log4net works fine in the 1.1 apps using log4net version 1.2.9.0 and but not the 3.5 web app. The logging works fine in a development and staging environment but not in production. It does not error and I receive no events logged in the event viewer and don't know where to look next. I have tried both versions of log4net (1.2.9.0 and 1.2.10.0) and both work in development and staging but not in production.

For testing purposes I have created just a single page application that just echos back the time when the page is hit and also is supposed to log to my logfile using log4net.

Here is my web.config file:

    <configSections>
    <!-- LOG4NET Configuration -->
    <section name="log4net"  type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" requirePermission="false" />
</configSections>

<log4net debug="true">
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="D:\DIF\Logs\TestApp\TestApp_"/>
        <param name="AppendToFile" value="true"/>
        <param name="RollingStyle" value="Date"/>
        <param name="DatePattern" value="yyyyMMdd\.\l\o\g"/>
        <param name="StaticLogFileName" value="false"/>
        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%date{HH:mm:ss} %C::%M [%-5level] - %message%newline"/>
        </layout>
    </appender>
    <root>
        <level value="ALL"/>
        <appender-ref ref="RollingFileAppender"/>
    </root>
</log4net>

Here is my log4net initialization:

        // Logging for the application
    private static ILog mlog = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    protected void Application_Start(object sender, EventArgs e)
    {
        try
        {
            // Start the configuration of the Logging
            XmlConfigurator.Configure();

            mlog.Info("Started logging for the TestApp Application.");
        }
        catch (Exception ex)
        {
            throw;
        }
    }

Any help would be greatly appreciated.

Thanks,

Jim

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

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

发布评论

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

评论(1

凤舞天涯 2024-09-01 16:35:11

如果它在开发和登台环境中工作,我会从怀疑权限开始。查看您的 3.5 应用程序是否可以写入与 log4net 输出位于同一位置的文件。

If it works in dev and staging environments I'd start by suspecting permissions. See if your 3.5 app can write to a file in the same location as the log4net output.

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