public bool Load() { //create the appdomain, base directory should be set to the packages base directory which should have the assembly containing the proxy in it AppDomainSetup setupInfo = new AppDomainSetup(); setupInfo.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; setupInfo.ApplicationName = _appDomainName; setupInfo.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; _appDomain = AppDomain.CreateDomain(_appDomainName, AppDomain.CurrentDomain.Evidence, setupInfo); try { //log4net.Repository.Hierarchy.Hierarchy hierachy = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository(); log.Debug("Creating domain proxy for AppDomain: " + _appDomainName); //create the domain proxy Type proxyType = typeof(AssemblyLoadProxy); _loadProxy = (AssemblyLoadProxy)_appDomain.CreateInstanceFrom(proxyType.Assembly.Location, proxyType.FullName).Unwrap(); _loadProxySponsor = new LifetimeSponsor(_loadProxy); log.Debug("Initializing cross-domain logging for AppDomain: " + _appDomainName); _loadProxy.InitializeLogging(new Logging.CrossDomainParentAppender()); } catch (Exception ex) { //log.Error("An error occurred initializing the domain proxy for AppDomain: " + _appDomainName, ex); //return false; throw; } return(true); }
protected virtual void Dispose(bool disposing) { if (disposing) { log.Debug("Begin dispose of AppDomain: " + _appDomainName); if (Sponsors.Count > 0) { log.Debug("Cleaning up cross-domain lifetime sponsors for AppDomain: " + _appDomainName); foreach (LifetimeSponsor sponsor in Sponsors) { sponsor.Dispose(); } } if (_loadProxy != null) { log.Debug("Closing domain proxy for AppDomain: " + _appDomainName); try { System.Runtime.Remoting.RemotingServices.Disconnect(_loadProxy); } catch { } _loadProxy = null; } if (_loadProxySponsor != null) { _loadProxySponsor.Dispose(); _loadProxySponsor = null; } if (_appDomain != null) { log.Debug("Unloading AppDomain: " + _appDomainName); AppDomain.Unload(_appDomain); } } }