[ 
https://issues.apache.org/jira/browse/LOG4NET-158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12600924#action_12600924
 ] 

Ron Grabowski commented on LOG4NET-158:
---------------------------------------

I thought that a new FileSystemWatcher was created each time the config file 
changed. That's not how the current implementation works. 

If it were the case then we could dispose the FileSystemWatcher and then call 
InternalConfigureAndWatch again:

private void OnWatchedFileChange(object state)
{
  // release resources being watched
 FileSystemWatcher watcher = (FileSystemWatcher)state;
 watcher.EnableRaisingEvents = false;
 watcher.Dispose();

 // re-create a new FileSystemWatcher using m_configFile
 // m_repository.ShutDown(); ???
 XmlConfigurator.InternalConfigureAndWatch(m_repository, m_configFile);
}

I'm not too worried about the cost of creating a new FileSystemWatcher because 
the config file isn't something that is likely to change a lot in a very small 
time period.

Doing it that way we shouldn't have to introduce any other variables or make 
ConfigureAndWatchHandler implement IDisposable. 

I don't think your #3 step would work because log4net supports multiple 
repositories. Its possible, albeit a bit unlikely, that someone could have two 
repositories running with each one having a file watch on a separate config 
file.

When configuring the repository over again I'd like to start from a clean slate 
each time and not have to worry about cleaning up from the last instance. 
Speaking of cleaning up...I suspect ShutDown() isn't being called on the 
repository before reconfiguring it to support log4net's "merge" functionality 
of the new config file. I don't know how well the "merge" functionality works 
to be quite honest. I think there is an open ticket on it.

Thoughts?

> 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.

Reply via email to