File lock error when using FileAppender with XmlConfigurator.ConfigureAndWatch (v3.3.1)
@FreeAndNil is already working on this.
Since Sep 19, 2026.
Assessment
This issue has not been assessed yet.
Description
When using the XmlConfigurator's file-watching, like this:
var logRepository = LogManager.GetRepository(typeof(Program).Assembly);
XmlConfigurator.ConfigureAndWatch(logRepository, new FileInfo("log.config"));
with a simple FileAppender config, like this:
<log4net>
<appender name="log.log" type="log4net.Appender.FileAppender">
<file value=".\log.log" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="log.log" />
</root>
</log4net>
When editing the config-file at run-time, you get:
log4net:ERROR [FileAppender] ErrorCode: GenericFailure. Unable to acquire lock on file ...\log.log. The process cannot access the file '...\log.log' because it is being used by another process.
Due the file-change, the appenders are getting re-configured.
v3.3.0 old appenders were stopped and removed before new appenders were created and added.
v3.3.1 new appenders are created before old appenders are stopped.
The old appender still has a lock on the file.
The new appender is created and calls ActivateOptions()->OpenFile().
- Dominant language
- C#
- Stars
- 934
- Forks
- 333
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 7
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/logging-log4net
-
.NET Matrix Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/logging-log4net#303 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
apache/logging-log4net#142 · 20 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
apache/logging-log4net#108 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
apache/logging-log4net#107 ·
All issues in apache/logging-log4net
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·