How to Solve log4net multi process access log file Error

<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<!--Log path-->
<param name="File" value="log/err/" />
<param name="Encoding" value="utf-8" />
<! -- Whether it is appending logs to the file -- >
<param name="AppendToFile" value="true" />
<! --log retention days -->
<param name="MaxSizeRollBackups" value="10" />
<! -- Whether the log file name is fixed -->
<param name="StaticLogFileName" value="false" />
<! -- Log file name formatted as:2008-08-31.log -->
<param name="DatePattern" value="yyyy-MM-dd&quot;error.log&quot;" />
<! -- Logs scroll by date-->
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<!-- <param name="Header" value="[Header] " /> -->
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
<!-- <param name="Footer" value="%n [Footer] " /> -->
<!-- <conversionPattern -->
<!-- value="&lt;HR COLOR=red>%n时间:%d [%t] &lt;BR>%n级别:%-5p &lt;BR>%n类:%c [%x] &lt;BR>%n%m &lt;BR>%n &lt;HR Size=1>" /> -->

</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMax" value="Error" />
<param name="LevelMin" value="Error" />
</filter>
</appender>

<root>
<!--(High) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (Low) -->
<level value="all" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
</configuration>

Reading a file by multiple processes will cause the log file to be occupied, as follows:
it is being used by another process, so the process cannot access this file

This configuration item needs to be added in log4net.config

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

Similar Posts: