Log4net unable to write, only creating empty files, but not writing actual logs

My guess would be that in your config file, you didn't specify a layout pattern. Normally, you have something that looks like this inside your appender:

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>

That specifies what to write to the log. If you don't have that, I doubt it will write anything.

I agree with those in the comments who said this probably isn't a permissions issue because the file gets created. To test that this is true, you could add an appender to your config that outputs to the console. Then you could watch the output as you debug your application. If that doesn't work either, you know the issue isn't a permissions issue.

The best suggestion I can give would be to compare your config file with a working one. Make sure that every section has a counterpart in the working config or that you know why it doesn't need to have one. Here is an article I wrote on log4net that includes explanations on every section of the config and it shows how to write them:

http://www.codeproject.com/KB/dotnet/Log4net_Tutorial.aspx

If all of this doesn't help, please post your config file text in your question so we can look through it.


One possible cause of this issue could be the Logging Level. Check if Logging level is set to FATAL and if that is the case try replacing this part of the web.config:

 <log4net>
         .....
         <root>
              <level value="FATAL" /> 
              <appender-ref ref="RollingFileAppender" />
            </root>
         .....
    </log4net>

with this:

<log4net>
    ......
    <root>
         <level value="DEBUG" /> 
           <appender-ref ref="RollingFileAppender" />
       </root>
    ....
</log4net>

Furthemore don't forget to check in web.config section the eventual occurences of some

 <filter type="log4net.Filter.StringMatchFilter">
    <stringToMatch value="test" />
  </filter>

subsection. In this case even though the logging level is set to DEBUG (for example) and you put in your code somethig like:

log.Debug("Db quering...");

it will always return blank but if you write for example:

log.Debug("test: Db quering...");

Try therefore to comment out the filter sections and also this line

  <filter type="log4net.Filter.DenyAllFilter" />

a this point finally you should get it working!!

Hope this helps