log4net RollingFileAppender and IIS 7.5

你离开我真会死。 提交于 2019-12-22 11:21:23

问题


I'm trying to use log4net with a RollingFileAppender on IIS 7.5 / Server 2008 R2. However, the configuration from my old IIS 6 / Server 2003 box doesn't appear to work anymore, I simply don't see any log files being created, here's what I've got setup:

In Web.config (inside <configSections>)

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

In the same file (inside <configuration>)

<log4net>
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
            </layout>
        </appender>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="..\\logs\\App" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <param name="StaticLogFileName" value="false" />
      <datePattern value=".yyyyMMdd.lo\g" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date | [%thread] | %-5level | %logger | %message %newline" />
      </layout>
    </appender>
    <logger name="AppLogger" additivity="false">
      <level value="All"/>
      <appender-ref ref="ConsoleAppender"/>
      <appender-ref ref="LogFileAppender"/>
    </logger>
</log4net>

The finally inside Global.asax I have:

protected void Application_Start()
{
    log4net.Config.XmlConfigurator.Configure();
}

This worked on Server 2003 and I can do the normal procedure of obtaining a reference to the logger and calling on the various methods (Debug, Error, etc). With IIS 7.5 / Server 2008 all the code executes properly (ie. all the pages still look ok) but there are no logs in the log output directory.

Anyone seen this before / got a workaround?

Thanks!


回答1:


It's most likely a permissions issue where the user (ASPNET) running under the process that is writing the log files does not have write permissions to that directory you are trying to log in. You should make sure that this user has write permissions to the folder in your config.




回答2:


Beware of the relative path of the log file.
Try with an absolute path to a folder that have the correct privileges. example:

<file value="C:\\logs\\App" />


来源:https://stackoverflow.com/questions/6903422/log4net-rollingfileappender-and-iis-7-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!