开发者

log4net waits until app pool recycle before logging to mssql2008 database

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">
 开发者_JS百科   <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?


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜