Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

    }
like image 925
user998405 Avatar asked Nov 07 '11 16:11

user998405


People also ask

Where is log file log4net?

The log4net. config file is located in the \Enterprise7\bin\ directory and is the configuration file for the log4net logging application.

Does log4net support structured logging?

log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.


1 Answers

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.

like image 118
rick schott Avatar answered Sep 28 '22 04:09

rick schott