views:

423

answers:

3

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 initalizes 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 a 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).

+3  A: 

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

<root>
  <level value="ALL" />
  <appender-ref ref="RollingFileAppender" />
</root>
tanascius
that didn't do it. One interesting thing is when running the website, it creates the .txt file, but it doesn't log anything in it. When I try to delete the file (while the web server process is still running) it says that the web server is currently using it...even after I've left the page that uses the logging ability (only one page uses logging).
contactmatt
@contactmatt: I am sorry, I can't help you much more. I copied your configuration to one of my programs (and added the appende-ref) and it worked as expected. Make sure you have the latest log4net release and that the config-file is up-to-date (start a rebuild, look into the file).
tanascius
A: 

Is it possible to run Debug View on the webserver?

If so, you may be able to see if log4net is reporting any errors (such as an access error or a error reading the configuration file)

sgmoore
+2  A: 

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>
contactmatt