Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very simple file appender logging not working

Here's my web.config information:

  <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      <log4net>
        <root>
                <level value="ALL" />
        </root>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
              <file value="c:\temp\log-file.txt" />
              <appendToFile value="true" />
              <rollingStyle value="Size" />
              <maxSizeRollBackups value="10" />
              <maximumFileSize value="1MB" />
              <staticLogFileName value="true" />
              <layout type="log4net.Layout.SimpleLayout" />
        </appender>
      </log4net>
...

Here's the code that initializes the logger:

protected void SendMessage()
    {
        log4net.Config.XmlConfigurator.Configure(); 
        ILog log = LogManager.GetLogger(typeof(Contact));
        ...
        log.Info("here we go!");
        log.Debug("debug afasf");
        ...
     }

It doesn't work, no matter what I seem to do. I am referencing the 'log4net.dll' correctly, and by debugging the application I can see that the log object is getting initiated properly. This is an asp.net 3.5 framework web project. Any ideas/suggestions?

I thought originally this error may be due to a file write permission constraint, but that doesn't seem to be the case (or so I think).

like image 530
contactmatt Avatar asked May 17 '10 15:05

contactmatt


3 Answers

I had to call fileAppender.ActivateOptions() to get it logging

like image 125
Andrew Avatar answered Nov 15 '22 10:11

Andrew


I found the answer: I needed the requirePermission="false" tag in my web.config's configuration seciton.

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" **requirePermission="false"**/>
</configSections>
like image 35
contactmatt Avatar answered Nov 15 '22 12:11

contactmatt


As far as I can see you are missing an appender for root:

<root>
  <level value="ALL" />
  <appender-ref ref="RollingFileAppender" />
</root>
like image 6
tanascius Avatar answered Nov 15 '22 12:11

tanascius