开发者

log4net RollingFileAppender and IIS 7.5

开发者 https://www.devze.com 2023-03-24 04:11 出处:网络
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 a

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 be开发者_如何学Cfore / got a workaround?

Thanks!


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.


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" />
0

精彩评论

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

关注公众号