I wrote a simple web page to display the log file in a textarea from a data synchronization application that logged all it's juicy details to a Rolling log file.
I fired up the page to see my creation and it worked... until the sync service was fired up and started writing to the log file. After that the blasted page just threw a IO exception at me--another process has an exclusive lock on the file and I can't READ it! Turns out it's the default locking mode for FileAppenders but you can configure whatever you are comfortable with.
<appender name=/"RollingFile/" type=/"log4net.Appender.RollingFileAppender/">
<layout type=/"log4net.Layout.PatternLayout/">
<conversionPattern value=/"%d [%t] %-5p %c{1} - %m%n/" />
</layout>
<file value=/"Application.log/" />
<appendToFile value=/"true/" />
<maximumFileSize value=/"500KB/" />
<maxSizeRollBackups value=/"5/" />
<lockingModel type=/"log4net.Appender.FileAppender+MinimalLock/" />
</appender>
The element configures the Appender to use a MinimalLock which only will acquire a lock while it's writing. It appears that it also uses FileShare.Read which will not lock others from just reading it.
It's amazing that this information was so hard to come by, or maybe I was just having a bad google day. At anyrate I thought I'd be a good netcitizen and blog about it so hopeful some poor sap can find this and speed up the troubleshooting--even if that poor sap is me :P
log4net 读取日志的问题资料
最新推荐文章于 2023-04-30 16:33:26 发布