[
https://issues.apache.org/jira/browse/LOG4NET-158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12601148#action_12601148
]
Ron Grabowski commented on LOG4NET-158:
---------------------------------------
This was the test case I used to see if the call to Dispose was releasing the
handle (Handle column in Process Explorer):
// this is really bad...don't do it!
while (true)
{
Thread.Sleep(1000);
log4net.Config.XmlConfigurator.ConfigureAndWatch(new
FileInfo("c:\\log4net.config"));
ILog programLog = LogManager.GetLogger(typeof(Program));
programLog.Info("Hello World");
}
The handle was still being leaked when I use various combinations of this code:
private void OnWatchedFileChange(object state)
{
// release resources being watched
FileSystemWatcher watcher = (FileSystemWatcher)state;
watcher.EnableRaisingEvents = false;
watcher.Dispose();
XmlConfigurator.InternalConfigure(m_repository, m_configFile);
}
I also tried hooking into the repository's ShutDownEvent and disposing the
FileSystemWatcher there too. None of those seemed to work.
If used properly (i.e. calling ConfigureAndWatch once) there are no handle
leaks...even if there are lots of changes detected on the file.
I implemented your solution and didn't see any leaks (uploaded patch to this
issue). I suppose we could apply it just to be safe.
> XMLConfigurator.ConfigureAndWatch() leaks resources if called multiple times
> ----------------------------------------------------------------------------
>
> Key: LOG4NET-158
> URL: https://issues.apache.org/jira/browse/LOG4NET-158
> Project: Log4net
> Issue Type: Bug
> Components: Other
> Affects Versions: 1.2.10
> Environment: Windows Server 2003, Windows XP
> Reporter: Strategic Insurance Software
>
> If XMLConfigurator.ConfigureAndWatch() is called multiple times within an
> AppDomain, each time it is called it leaks a Win32 file handle (possibly
> from a FileSystemWatcher object not being disposed?) to the folder containing
> the previous configuration file it was watching.
> Desired behavior would be to release the handle to the folder containing the
> previous configuration file.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.