Search code examples
c#asp.netiislog4netpublish

log4net cant create log file , when publish to server


I am using log4net for logging my asp.net application. However the log file is working well when I run on my localhost. But when I publish to IIS, the log4net is not able to create a log file. May I know what is the problem? Did I miss any configuration?

Here is my log4net.config.

 <log4net debug="true">
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
  <param name="File" value="D:\\LewreLogFile1.log"/>
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="10MB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
  </layout>
</appender>
<logger name="File">
  <level value="All" />
</logger>
<root>
  <level value="All" />
  <appender-ref ref="LogFileAppender" />
</root>

and my global.asax

 void Application_Start(object sender, EventArgs e)
    {
        string l4net = Server.MapPath("~/log4Net.config");
        log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(l4net));

    }

Solution

  • You have to give IIS permission to do IO. Change your App pool identity or give IUSR permission the the file system it's trying to access.