I’ve got a MVC3 website that I’ve just started. I’d like to add logging to this site, and decided to go with Log4Net. I used this tutorial for setting this up, and it works somewhat, but it isn’t working as I expected.
I set up my logging per the instructions found on the site I was using for instructions. I ran the site using the debugger and it should have logged a record when the Index action on the Home controller was called.
I checked the table and it was empty. I stopped the debugger and checked my config file. Everything looked OK. I then put a break point on the line of code where the logging was done. The code was hit, but still nothing in my log table.
I decided to turn on the log4net debugging. I modified my web.config and started the debugger again. Now when I checked my table, it showed two entries, but I noticed the time stamp was a few minutes old.
After additional testing, I found the logger was only flushing to my table when I modified the web.config file.
First of all, is this normal behavior?
If not, is there a way to get log4net to log without me stopping my website?
Thanks
Update with solution
Once the answer was provided by @tawman, I could then search on BufferSize. This was the reason for the problem I encountered.
BufferSize is the number of Logs that will be queued before any are written. I changed this value to 1 (as opposed to the 100 suggested – The default is 500).
This has my logs writing immediately. I don’t know if there are any performance implications with a setting of 1, but I will have to look into this.
Change the buffer size to a smaller setting log4net Config Examples