Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net waits until app pool recycle before logging to mssql2008 database

Tags:

log4net

I'm configuring log4net with:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "../ProjectName/Log4Net.config", Watch = true)]

I have 2 appenders configured: 1. An AdoNetAppender logging to a Log table on a mssql2008 database. 2. A FileAppender that just looks like this:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
  <file value="c:\log-file.txt" />
  <appendToFile value="true" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>

The problem is that when an action gets logged, it immediately appears in log-file.txt. It doesn't appear as an entry in the database until I either do iisreset, recompile the web code, or recycle the app pool.

The configuration seems right as the action does eventually get logged to the database. I just don't understand why the delay.

Can anybody give me a reason or tell me how to fix it?

like image 455
Rui Jiang Avatar asked Oct 30 '10 21:10

Rui Jiang


1 Answers

The AdoNetAppender is a buffered appender. If you want it to write directly to the database you need to set the buffer size to 1:

<bufferSize value="1" />
like image 101
Stefan Egli Avatar answered Oct 09 '22 15:10

Stefan Egli