nicko       2004/12/05 18:19:10

  Modified:    src/Core IRepositorySelector.cs CompactRepositorySelector.cs
                        DefaultRepositorySelector.cs
  Log:
  Added ExistsReposiotry method to IRepositorySelector. Updated doc comments
  
  Revision  Changes    Path
  1.3       +91 -22    logging-log4net/src/Core/IRepositorySelector.cs
  
  Index: IRepositorySelector.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Core/IRepositorySelector.cs,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IRepositorySelector.cs    16 Feb 2004 02:10:52 -0000      1.2
  +++ IRepositorySelector.cs    6 Dec 2004 02:19:09 -0000       1.3
  @@ -32,7 +32,9 @@
        /// <param name="e">The <see cref="LoggerRepositoryCreationEventArgs"/> 
event args
        /// that holds the <see cref="ILoggerRepository"/> instance that has 
been created.</param>
        /// <remarks>
  -     /// Delegate used to handle logger repository creation event 
notifications
  +     /// <para>
  +     /// Delegate used to handle logger repository creation event 
notifications.
  +     /// </para>
        /// </remarks>
        public delegate void LoggerRepositoryCreationEventHandler(object 
sender, LoggerRepositoryCreationEventArgs e);
   
  @@ -40,8 +42,10 @@
        /// Provides data for the <see 
cref="IRepositorySelector.LoggerRepositoryCreatedEvent"/> event.
        /// </summary>
        /// <remarks>
  -     /// A <see cref="IRepositorySelector.LoggerRepositoryCreatedEvent"/> 
event is raised every time a
  -     /// <see cref="ILoggerRepository"/> is created.
  +     /// <para>
  +     /// A <see cref="IRepositorySelector.LoggerRepositoryCreatedEvent"/> 
  +     /// event is raised every time a <see cref="ILoggerRepository"/> is 
created.
  +     /// </para>
        /// </remarks>
        public class LoggerRepositoryCreationEventArgs : EventArgs
        {
  @@ -54,6 +58,11 @@
                /// Construct instance using <see cref="ILoggerRepository"/> 
specified
                /// </summary>
                /// <param name="repository">the <see 
cref="ILoggerRepository"/> that has been created</param>
  +             /// <remarks>
  +             /// <para>
  +             /// Construct instance using <see cref="ILoggerRepository"/> 
specified
  +             /// </para>
  +             /// </remarks>
                public LoggerRepositoryCreationEventArgs(ILoggerRepository 
repository)
                {
                        m_repository = repository;
  @@ -65,6 +74,11 @@
                /// <value>
                /// The <see cref="ILoggerRepository"/> that has been created
                /// </value>
  +             /// <remarks>
  +             /// <para>
  +             /// The <see cref="ILoggerRepository"/> that has been created
  +             /// </para>
  +             /// </remarks>
                public ILoggerRepository LoggerRepository
                {
                        get { return m_repository; }
  @@ -74,11 +88,14 @@
        #endregion
   
        /// <summary>
  -     /// Interface used my the <see cref="LogManager"/> to select the <see 
cref="ILoggerRepository"/>.
  +     /// Interface used by the <see cref="LogManager"/> to select the <see 
cref="ILoggerRepository"/>.
        /// </summary>
        /// <remarks>
  -     /// The <see cref="LogManager"/> uses a <see 
cref="IRepositorySelector"/> to specify the policy for
  -     /// selecting the correct <see cref="ILoggerRepository"/> to return to 
the caller.
  +     /// <para>
  +     /// The <see cref="LogManager"/> uses a <see 
cref="IRepositorySelector"/> 
  +     /// to specify the policy for selecting the correct <see 
cref="ILoggerRepository"/> 
  +     /// to return to the caller.
  +     /// </para>
        /// </remarks>
        /// <author>Nicko Cadell</author>
        /// <author>Gert Driesen</author>
  @@ -87,49 +104,93 @@
                /// <summary>
                /// Gets the <see cref="ILoggerRepository"/> for the specified 
assembly.
                /// </summary>
  -             /// <param name="domainAssembly">The assembly to use to lookup 
to the <see cref="ILoggerRepository"/></param>
  +             /// <param name="assembly">The assembly to use to lookup to the 
<see cref="ILoggerRepository"/></param>
                /// <returns>The <see cref="ILoggerRepository"/> for the 
assembly.</returns>
  -             ILoggerRepository GetRepository(Assembly domainAssembly);
  +             /// <remarks>
  +             /// <para>
  +             /// Gets the <see cref="ILoggerRepository"/> for the specified 
assembly.
  +             /// </para>
  +             /// <para>
  +             /// How the association between <see cref="Assembly"/> and <see 
cref="ILoggerRepository"/>
  +             /// is made is not defined. The implementation may choose any 
method for
  +             /// this association. The results of this method must be 
repeatable, i.e.
  +             /// when called again with the same arguments the result must 
be the
  +             /// save value.
  +             /// </para>
  +             /// </remarks>
  +             ILoggerRepository GetRepository(Assembly assembly);
   
                /// <summary>
  -             /// Gets the <see cref="ILoggerRepository"/> for the specified 
domain
  +             /// Gets the named <see cref="ILoggerRepository"/>.
                /// </summary>
  -             /// <param name="domain">The domain to use to lookup to the 
<see cref="ILoggerRepository"/>.</param>
  -             /// <returns>The <see cref="ILoggerRepository"/> for the 
domain.</returns>
  -             ILoggerRepository GetRepository(string domain);
  +             /// <param name="repositoryName">The name to use to lookup to 
the <see cref="ILoggerRepository"/>.</param>
  +             /// <returns>The named <see cref="ILoggerRepository"/></returns>
  +             /// <remarks>
  +             /// Lookup a named <see cref="ILoggerRepository"/>. This is the 
repository created by
  +             /// calling <see cref="CreateRepository(string,Type)"/>.
  +             /// </remarks>
  +             ILoggerRepository GetRepository(string repositoryName);
   
                /// <summary>
                /// Creates a new repository for the assembly specified.
                /// </summary>
  -             /// <param name="domainAssembly">The assembly to use to create 
the domain to associate with the <see cref="ILoggerRepository"/>.</param>
  +             /// <param name="assembly">The assembly to use to create the 
domain to associate with the <see cref="ILoggerRepository"/>.</param>
                /// <param name="repositoryType">The type of repository to 
create, must implement <see cref="ILoggerRepository"/>.</param>
                /// <returns>The repository created.</returns>
                /// <remarks>
  -             /// <para>The <see cref="ILoggerRepository"/> created will be 
associated with the domain
  +             /// <para>
  +             /// The <see cref="ILoggerRepository"/> created will be 
associated with the domain
                /// specified such that a call to <see 
cref="GetRepository(Assembly)"/> with the
  -             /// same assembly specified will return the same repository 
instance.</para>
  +             /// same assembly specified will return the same repository 
instance.
  +             /// </para>
  +             /// <para>
  +             /// How the association between <see cref="Assembly"/> and <see 
cref="ILoggerRepository"/>
  +             /// is made is not defined. The implementation may choose any 
method for
  +             /// this association.
  +             /// </para>
                /// </remarks>
  -             ILoggerRepository CreateRepository(Assembly domainAssembly, 
Type repositoryType);
  +             ILoggerRepository CreateRepository(Assembly assembly, Type 
repositoryType);
   
                /// <summary>
  -             /// Creates a new repository for the domain specified.
  +             /// Creates a new repository with the name specified.
                /// </summary>
  -             /// <param name="domain">The domain to associate with the <see 
cref="ILoggerRepository"/>.</param>
  +             /// <param name="repositoryName">The name to associate with the 
<see cref="ILoggerRepository"/>.</param>
                /// <param name="repositoryType">The type of repository to 
create, must implement <see cref="ILoggerRepository"/>.</param>
                /// <returns>The repository created.</returns>
                /// <remarks>
  -             /// <para>The <see cref="ILoggerRepository"/> created will be 
associated with the domain
  +             /// <para>
  +             /// The <see cref="ILoggerRepository"/> created will be 
associated with the name
                /// specified such that a call to <see 
cref="GetRepository(string)"/> with the
  -             /// same domain specified will return the same repository 
instance.</para>
  +             /// same name will return the same repository instance.
  +             /// </para>
  +             /// </remarks>
  +             ILoggerRepository CreateRepository(string repositoryName, Type 
repositoryType);
  +
  +             /// <summary>
  +             /// Test if a named repository exists
  +             /// </summary>
  +             /// <param name="repositoryName">the named repository to 
check</param>
  +             /// <returns><c>true</c> if the repository exists</returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Test if a named repository exists. Use <see 
cref="CreateRepository"/>
  +             /// to create a new repository and <see cref="GetRepository"/> 
to retrieve 
  +             /// a repository.
  +             /// </para>
                /// </remarks>
  -             ILoggerRepository CreateRepository(string domain, Type 
repositoryType);
  +             bool ExistsRepository(string repositoryName);
   
                /// <summary>
  -             /// Gets the list of currently defined repositories.
  +             /// Gets an array of all currently defined repositories.
                /// </summary>
                /// <returns>
                /// An array of the <see cref="ILoggerRepository"/> instances 
created by 
                /// this <see cref="IRepositorySelector"/>.</returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Gets an array of all of the repositories created by this 
selector.
  +             /// </para>
  +             /// </remarks>
                ILoggerRepository[] GetAllRepositories();
   
                /// <summary>
  @@ -138,6 +199,14 @@
                /// <value>
                /// Event to notify that a logger repository has been created.
                /// </value>
  +             /// <remarks>
  +             /// <para>
  +             /// Event raised when a new repository is created.
  +             /// The event source will be this selector. The event args will
  +             /// be a <see cref="LoggerRepositoryCreationEventArgs"/> which
  +             /// holds the newly created <see cref="ILoggerRepository"/>.
  +             /// </para>
  +             /// </remarks>
                event LoggerRepositoryCreationEventHandler 
LoggerRepositoryCreatedEvent;
        }
   }
  
  
  
  1.7       +122 -35   logging-log4net/src/Core/CompactRepositorySelector.cs
  
  Index: CompactRepositorySelector.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Core/CompactRepositorySelector.cs,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CompactRepositorySelector.cs      1 Oct 2004 21:02:16 -0000       1.6
  +++ CompactRepositorySelector.cs      6 Dec 2004 02:19:09 -0000       1.7
  @@ -32,6 +32,16 @@
        /// for use with the compact framework
        /// </summary>
        /// <remarks>
  +     /// <para>
  +     /// This <see cref="IRepositorySelector"/> implementation is a simple
  +     /// mapping between repository name and <see cref="ILoggerRepository"/>
  +     /// object.
  +     /// </para>
  +     /// <para>
  +     /// The .NET Compact Framework 1.0 does not support retrieving assembly
  +     /// level attributes therefore unlike the 
<c>DefaultRepositorySelector</c>
  +     /// this selector does not examine the calling assembly for attributes.
  +     /// </para>
        /// </remarks>
        /// <author>Nicko Cadell</author>
        public class CompactRepositorySelector : IRepositorySelector
  @@ -40,8 +50,8 @@
   
                private const string DefaultRepositoryName = 
"log4net-default-repository";
   
  -             private IDictionary m_name2repositoryMap = new Hashtable();
  -             private Type m_defaultRepositoryType;
  +             private readonly Hashtable m_name2repositoryMap = new 
Hashtable();
  +             private readonly Type m_defaultRepositoryType;
   
                private event LoggerRepositoryCreationEventHandler 
m_loggerRepositoryCreatedEvent;
   
  @@ -53,6 +63,13 @@
                /// Create a new repository selector
                /// </summary>
                /// <param name="defaultRepositoryType">the type of the 
repositories to create, must implement <see cref="ILoggerRepository"/></param>
  +             /// <remarks>
  +             /// <para>
  +             /// Create an new compact repository selector.
  +             /// The default type for repositories must be specified,
  +             /// an appropriate value would be <see 
cref="log4net.Repository.Hierarchy.Hierarchy"/>.
  +             /// </para>
  +             /// </remarks>
                /// <exception cref="ArgumentNullException">throw if <paramref 
name="defaultRepositoryType"/> is null</exception>
                /// <exception cref="ArgumentOutOfRangeException">throw if 
<paramref name="defaultRepositoryType"/> does not implement <see 
cref="ILoggerRepository"/></exception>
                public CompactRepositorySelector(Type defaultRepositoryType)
  @@ -80,38 +97,52 @@
                /// <summary>
                /// Get the <see cref="ILoggerRepository"/> for the specified 
assembly
                /// </summary>
  -             /// <param name="assembly">the assembly to use to lookup to the 
<see cref="ILoggerRepository"/></param>
  -             /// <returns>The <see cref="ILoggerRepository"/> for the 
assembly</returns>
  +             /// <param name="assembly">not used</param>
  +             /// <returns>The default <see 
cref="ILoggerRepository"/></returns>
                /// <remarks>
  -             /// <para>Assemblies use the default repository.</para>
  +             /// <para>
  +             /// The <paramref name="assembly"/> argument is not used. This 
selector does not create a
  +             /// separate repository for each assembly. 
  +             /// </para>
  +             /// <para>
  +             /// As a named repository is not specified the default 
repository is 
  +             /// returned. The default repository is named 
<c>log4net-default-repository</c>.
  +             /// </para>
                /// </remarks>
  -             /// <exception cref="ArgumentNullException">throw if <paramref 
name="assembly"/> is null</exception>
                public ILoggerRepository GetRepository(Assembly assembly)
                {
                        return CreateRepository(assembly, 
m_defaultRepositoryType);
                }
   
                /// <summary>
  -             /// Get the <see cref="ILoggerRepository"/> for the specified 
repository
  +             /// Get the named <see cref="ILoggerRepository"/>
                /// </summary>
  -             /// <param name="repository">the repository to use to lookup to 
the <see cref="ILoggerRepository"/></param>
  -             /// <returns>The <see cref="ILoggerRepository"/> for the 
repository</returns>
  -             /// <exception cref="ArgumentNullException">throw if <paramref 
name="repository"/> is null</exception>
  -             /// <exception cref="LogException">throw if the <paramref 
name="repository"/> does not exist</exception>
  -             public ILoggerRepository GetRepository(string repository)
  +             /// <param name="repositoryName">the name of the repository to 
lookup</param>
  +             /// <returns>The named <see cref="ILoggerRepository"/></returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Get the named <see cref="ILoggerRepository"/>. The default 
  +             /// repository is <c>log4net-default-repository</c>. Other 
repositories 
  +             /// must be created using the <see 
cref="CreateRepository(string,Type)"/>.
  +             /// If the named repository does not exist an exception is 
thrown.
  +             /// </para>
  +             /// </remarks>
  +             /// <exception cref="ArgumentNullException">throw if <paramref 
name="repositoryName"/> is null</exception>
  +             /// <exception cref="LogException">throw if the <paramref 
name="repositoryName"/> does not exist</exception>
  +             public ILoggerRepository GetRepository(string repositoryName)
                {
  -                     if (repository == null)
  +                     if (repositoryName == null)
                        {
  -                             throw new ArgumentNullException("repository");
  +                             throw new 
ArgumentNullException("repositoryName");
                        }
   
                        lock(this)
                        {
                                // Lookup in map
  -                             ILoggerRepository rep = 
m_name2repositoryMap[repository] as ILoggerRepository;
  +                             ILoggerRepository rep = 
m_name2repositoryMap[repositoryName] as ILoggerRepository;
                                if (rep == null)
                                {
  -                                     throw new LogException("Repository 
["+repository+"] is NOT defined.");
  +                                     throw new LogException("Repository 
["+repositoryName+"] is NOT defined.");
                                }
                                return rep;
                        }
  @@ -120,17 +151,23 @@
                /// <summary>
                /// Create a new repository for the assembly specified 
                /// </summary>
  -             /// <param name="assembly">the assembly to use to create the 
repository to associate with the <see cref="ILoggerRepository"/></param>
  +             /// <param name="assembly">not used</param>
                /// <param name="repositoryType">the type of repository to 
create, must implement <see cref="ILoggerRepository"/></param>
                /// <returns>the repository created</returns>
                /// <remarks>
  -             /// <para>The <see cref="ILoggerRepository"/> created will be 
associated with the repository
  -             /// specified such that a call to <see 
cref="GetRepository(Assembly)"/> with the
  -             /// same assembly specified will return the same repository 
instance.</para>
  -             /// 
  -             /// <para>Assemblies use the default repository.</para>
  +             /// <para>
  +             /// The <paramref name="assembly"/> argument is not used. This 
selector does not create a
  +             /// separate repository for each assembly. 
  +             /// </para>
  +             /// <para>
  +             /// If the <paramref name="repositoryType"/> is <c>null</c> 
then the
  +             /// default repository type specified to the constructor is 
used.
  +             /// </para>
  +             /// <para>
  +             /// As a named repository is not specified the default 
repository is 
  +             /// returned. The default repository is named 
<c>log4net-default-repository</c>.
  +             /// </para>
                /// </remarks>
  -             /// <exception cref="ArgumentNullException">throw if <paramref 
name="assembly"/> is null</exception>
                public ILoggerRepository CreateRepository(Assembly assembly, 
Type repositoryType)
                {
                        // If the type is not set then use the default type
  @@ -141,6 +178,8 @@
   
                        lock(this)
                        {
  +                             // This method should not throw if the default 
repository already exists.
  +
                                // First check that the repository does not 
exist
                                ILoggerRepository rep = 
m_name2repositoryMap[DefaultRepositoryName] as ILoggerRepository;
                                if (rep == null)
  @@ -156,22 +195,31 @@
                /// <summary>
                /// Create a new repository for the repository specified
                /// </summary>
  -             /// <param name="repository">the repository to associate with 
the <see cref="ILoggerRepository"/></param>
  +             /// <param name="repositoryName">the repository to associate 
with the <see cref="ILoggerRepository"/></param>
                /// <param name="repositoryType">the type of repository to 
create, must implement <see cref="ILoggerRepository"/>.
                /// If this param is null then the default repository type is 
used.</param>
                /// <returns>the repository created</returns>
                /// <remarks>
  +             /// <para>
                /// The <see cref="ILoggerRepository"/> created will be 
associated with the repository
                /// specified such that a call to <see 
cref="GetRepository(string)"/> with the
                /// same repository specified will return the same repository 
instance.
  +             /// </para>
  +             /// <para>
  +             /// If the named repository already exists an exception will be 
thrown.
  +             /// </para>
  +             /// <para>
  +             /// If <paramref name="repositoryType"/> is <c>null</c> then 
the default 
  +             /// repository type specified to the constructor is used.
  +             /// </para>
                /// </remarks>
  -             /// <exception cref="ArgumentNullException">throw if <paramref 
name="repository"/> is null</exception>
  -             /// <exception cref="LogException">throw if the <paramref 
name="repository"/> already exists</exception>
  -             public ILoggerRepository CreateRepository(string repository, 
Type repositoryType)
  +             /// <exception cref="ArgumentNullException">throw if <paramref 
name="repositoryName"/> is null</exception>
  +             /// <exception cref="LogException">throw if the <paramref 
name="repositoryName"/> already exists</exception>
  +             public ILoggerRepository CreateRepository(string 
repositoryName, Type repositoryType)
                {
  -                     if (repository == null)
  +                     if (repositoryName == null)
                        {
  -                             throw new ArgumentNullException("repository");
  +                             throw new 
ArgumentNullException("repositoryName");
                        }
   
                        // If the type is not set then use the default type
  @@ -185,23 +233,23 @@
                                ILoggerRepository rep = null;
   
                                // First check that the repository does not 
exist
  -                             rep = m_name2repositoryMap[repository] as 
ILoggerRepository;
  +                             rep = m_name2repositoryMap[repositoryName] as 
ILoggerRepository;
                                if (rep != null)
                                {
  -                                     throw new LogException("Repository 
["+repository+"] is already defined. Repositories cannot be redefined.");
  +                                     throw new LogException("Repository 
["+repositoryName+"] is already defined. Repositories cannot be redefined.");
                                }
                                else
                                {
  -                                     
LogLog.Debug("DefaultRepositorySelector: Creating repository ["+repository+"] 
using type ["+repositoryType+"]");
  +                                     
LogLog.Debug("DefaultRepositorySelector: Creating repository 
["+repositoryName+"] using type ["+repositoryType+"]");
   
                                        // Call the no arg constructor for the 
repositoryType
                                        rep = 
(ILoggerRepository)Activator.CreateInstance(repositoryType);
   
                                        // Set the name of the repository
  -                                     rep.Name = repository;
  +                                     rep.Name = repositoryName;
   
                                        // Store in map
  -                                     m_name2repositoryMap[repository] = rep;
  +                                     m_name2repositoryMap[repositoryName] = 
rep;
   
                                        // Notify listeners that the repository 
has been created
                                        OnLoggerRepositoryCreatedEvent(rep);
  @@ -212,9 +260,34 @@
                }
   
                /// <summary>
  -             /// Copy the list of <see cref="ILoggerRepository"/> objects
  +             /// Test if a named repository exists
  +             /// </summary>
  +             /// <param name="repositoryName">the named repository to 
check</param>
  +             /// <returns><c>true</c> if the repository exists</returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Test if a named repository exists. Use <see 
cref="CreateRepository"/>
  +             /// to create a new repository and <see cref="GetRepository"/> 
to retrieve 
  +             /// a repository.
  +             /// </para>
  +             /// </remarks>
  +             public bool ExistsRepository(string repositoryName)
  +             {
  +                     lock(this)
  +                     {
  +                             return 
m_name2repositoryMap.ContainsKey(repositoryName);
  +                     }
  +             }
  +
  +             /// <summary>
  +             /// Gets a list of <see cref="ILoggerRepository"/> objects
                /// </summary>
                /// <returns>an array of all known <see 
cref="ILoggerRepository"/> objects</returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Gets an array of all of the repositories created by this 
selector.
  +             /// </para>
  +             /// </remarks>
                public ILoggerRepository[] GetAllRepositories()
                {
                        lock(this)
  @@ -234,6 +307,14 @@
                /// <value>
                /// Event to notify that a logger repository has been created.
                /// </value>
  +             /// <remarks>
  +             /// <para>
  +             /// Event raised when a new repository is created.
  +             /// The event source will be this selector. The event args will
  +             /// be a <see cref="LoggerRepositoryCreationEventArgs"/> which
  +             /// holds the newly created <see cref="ILoggerRepository"/>.
  +             /// </para>
  +             /// </remarks>
                public event LoggerRepositoryCreationEventHandler 
LoggerRepositoryCreatedEvent
                {
                        add { m_loggerRepositoryCreatedEvent += value; }
  @@ -244,6 +325,12 @@
                /// Notify the registered listeners that the repository has 
been created
                /// </summary>
                /// <param name="repository">The repository that has been 
created</param>
  +             /// <remarks>
  +             /// <para>
  +             /// Raises the <event 
cref="LoggerRepositoryCreatedEvent">LoggerRepositoryCreatedEvent</event>
  +             /// event.
  +             /// </para>
  +             /// </remarks>
                protected virtual void 
OnLoggerRepositoryCreatedEvent(ILoggerRepository repository)
                {
                        LoggerRepositoryCreationEventHandler handler = 
m_loggerRepositoryCreatedEvent;
  
  
  
  1.10      +89 -30    logging-log4net/src/Core/DefaultRepositorySelector.cs
  
  Index: DefaultRepositorySelector.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Core/DefaultRepositorySelector.cs,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultRepositorySelector.cs      15 Nov 2004 02:51:46 -0000      1.9
  +++ DefaultRepositorySelector.cs      6 Dec 2004 02:19:09 -0000       1.10
  @@ -35,8 +35,10 @@
        /// The default implementation of the <see cref="IRepositorySelector"/> 
interface.
        /// </summary>
        /// <remarks>
  +     /// <para>
        /// Uses attributes defined on the calling assembly to determine how to
        /// configure the hierarchy for the repository.
  +     /// </para>
        /// </remarks>
        /// <author>Nicko Cadell</author>
        /// <author>Gert Driesen</author>
  @@ -50,6 +52,14 @@
                /// <value>
                /// Event to notify that a logger repository has been created.
                /// </value>
  +             /// <remarks>
  +             /// <para>
  +             /// Event raised when a new repository is created.
  +             /// The event source will be this selector. The event args will
  +             /// be a <see cref="LoggerRepositoryCreationEventArgs"/> which
  +             /// holds the newly created <see cref="ILoggerRepository"/>.
  +             /// </para>
  +             /// </remarks>
                public event LoggerRepositoryCreationEventHandler 
LoggerRepositoryCreatedEvent 
                {
                        add { m_loggerRepositoryCreatedEvent += value; }
  @@ -64,6 +74,13 @@
                /// Creates a new repository selector.
                /// </summary>
                /// <param name="defaultRepositoryType">The type of the 
repositories to create, must implement <see cref="ILoggerRepository"/></param>
  +             /// <remarks>
  +             /// <para>
  +             /// Create an new repository selector.
  +             /// The default type for repositories must be specified,
  +             /// an appropriate value would be <see 
cref="log4net.Repository.Hierarchy.Hierarchy"/>.
  +             /// </para>
  +             /// </remarks>
                /// <exception cref="ArgumentNullException"><paramref 
name="defaultRepositoryType"/> is <see langword="null" />.</exception>
                /// <exception cref="ArgumentOutOfRangeException"><paramref 
name="defaultRepositoryType"/> does not implement <see 
cref="ILoggerRepository"/>.</exception>
                public DefaultRepositorySelector(Type defaultRepositoryType)
  @@ -109,8 +126,8 @@
                /// the <paramref name="assembly"/>.
                /// </para>
                /// </remarks>
  -             /// <exception cref="ArgumentNullException"><paramref 
name="assembly"/> is <see langword="null" />.</exception>
                /// <returns>The <see cref="ILoggerRepository"/> for the 
assembly</returns>
  +             /// <exception cref="ArgumentNullException"><paramref 
name="assembly"/> is <see langword="null" />.</exception>
                public ILoggerRepository GetRepository(Assembly 
repositoryAssembly)
                {
                        if (repositoryAssembly == null)
  @@ -123,24 +140,34 @@
                /// <summary>
                /// Gets the <see cref="ILoggerRepository"/> for the specified 
repository.
                /// </summary>
  -             /// <param name="repository">The repository to use to lookup 
the <see cref="ILoggerRepository"/>.</param>
  +             /// <param name="repositoryName">The repository to use to 
lookup the <see cref="ILoggerRepository"/>.</param>
                /// <returns>The <see cref="ILoggerRepository"/> for the 
specified repository.</returns>
  -             /// <exception cref="ArgumentNullException"><paramref 
name="repository"/> is <see langword="null" />.</exception>
  -             /// <exception cref="LogException"><paramref 
name="repository"/> does not exist.</exception>
  -             public ILoggerRepository GetRepository(string repository)
  +             /// <remarks>
  +             /// <para>
  +             /// Returns the named repository. If <paramref 
name="repositoryName"/> is <c>null</c>
  +             /// a <see cref="ArgumentNullException"/> is thrown. If the 
repository 
  +             /// does not exist a <see cref="LogException"/> is thrown.
  +             /// </para>
  +             /// <para>
  +             /// Use <see cref="CreateRepository(string,Type)"/> to create a 
repository.
  +             /// </para>
  +             /// </remarks>
  +             /// <exception cref="ArgumentNullException"><paramref 
name="repositoryName"/> is <see langword="null" />.</exception>
  +             /// <exception cref="LogException"><paramref 
name="repositoryName"/> does not exist.</exception>
  +             public ILoggerRepository GetRepository(string repositoryName)
                {
  -                     if (repository == null)
  +                     if (repositoryName == null)
                        {
  -                             throw new ArgumentNullException("repository");
  +                             throw new 
ArgumentNullException("repositoryName");
                        }
   
                        lock(this)
                        {
                                // Lookup in map
  -                             ILoggerRepository rep = 
m_name2repositoryMap[repository] as ILoggerRepository;
  +                             ILoggerRepository rep = 
m_name2repositoryMap[repositoryName] as ILoggerRepository;
                                if (rep == null)
                                {
  -                                     throw new LogException("Repository [" + 
repository + "] is NOT defined.");
  +                                     throw new LogException("Repository [" + 
repositoryName + "] is NOT defined.");
                                }
                                return rep;
                        }
  @@ -298,22 +325,24 @@
                /// <summary>
                /// Creates a new repository for the specified repository.
                /// </summary>
  -             /// <param name="repository">The repository to associate with 
the <see cref="ILoggerRepository"/>.</param>
  +             /// <param name="repositoryName">The repository to associate 
with the <see cref="ILoggerRepository"/>.</param>
                /// <param name="repositoryType">The type of repository to 
create, must implement <see cref="ILoggerRepository"/>.
                /// If this param is <see langword="null" /> then the default 
repository type is used.</param>
                /// <returns>The new repository.</returns>
                /// <remarks>
  +             /// <para>
                /// The <see cref="ILoggerRepository"/> created will be 
associated with the repository
                /// specified such that a call to <see 
cref="GetRepository(string)"/> with the
                /// same repository specified will return the same repository 
instance.
  +             /// </para>
                /// </remarks>
  -             /// <exception cref="ArgumentNullException"><paramref 
name="repository"/> is <see langword="null" />.</exception>
  -             /// <exception cref="LogException"><paramref 
name="repository"/> already exists.</exception>
  -             public ILoggerRepository CreateRepository(string repository, 
Type repositoryType)
  +             /// <exception cref="ArgumentNullException"><paramref 
name="repositoryName"/> is <see langword="null" />.</exception>
  +             /// <exception cref="LogException"><paramref 
name="repositoryName"/> already exists.</exception>
  +             public ILoggerRepository CreateRepository(string 
repositoryName, Type repositoryType)
                {
  -                     if (repository == null)
  +                     if (repositoryName == null)
                        {
  -                             throw new ArgumentNullException("repository");
  +                             throw new 
ArgumentNullException("repositoryName");
                        }
   
                        // If the type is not set then use the default type
  @@ -327,15 +356,15 @@
                                ILoggerRepository rep = null;
   
                                // First check that the repository does not 
exist
  -                             rep = m_name2repositoryMap[repository] as 
ILoggerRepository;
  +                             rep = m_name2repositoryMap[repositoryName] as 
ILoggerRepository;
                                if (rep != null)
                                {
  -                                     throw new LogException("Repository [" + 
repository + "] is already defined. Repositories cannot be redefined.");
  +                                     throw new LogException("Repository [" + 
repositoryName + "] is already defined. Repositories cannot be redefined.");
                                }
                                else
                                {
                                        // Lookup an alias before trying to 
create the new repository
  -                                     ILoggerRepository aliasedRepository = 
m_alias2repositoryMap[repository] as ILoggerRepository;
  +                                     ILoggerRepository aliasedRepository = 
m_alias2repositoryMap[repositoryName] as ILoggerRepository;
                                        if (aliasedRepository != null)
                                        {
                                                // Found an alias
  @@ -344,16 +373,16 @@
                                                if (aliasedRepository.GetType() 
== repositoryType)
                                                {
                                                        // Repository type is 
compatible
  -                                                     
LogLog.Debug("DefaultRepositorySelector: Aliasing repository [" + repository + 
"] to existing repository [" + aliasedRepository.Name + "]");
  +                                                     
LogLog.Debug("DefaultRepositorySelector: Aliasing repository [" + 
repositoryName + "] to existing repository [" + aliasedRepository.Name + "]");
                                                        rep = aliasedRepository;
   
                                                        // Store in map
  -                                                     
m_name2repositoryMap[repository] = rep;
  +                                                     
m_name2repositoryMap[repositoryName] = rep;
                                                }
                                                else
                                                {
                                                        // Invalid repository 
type for alias
  -                                                     
LogLog.Error("DefaultRepositorySelector: Failed to alias repository [" + 
repository + "] to existing repository ["+aliasedRepository.Name+"]. Requested 
repository type ["+repositoryType.FullName+"] is not compatible with existing 
type [" + aliasedRepository.GetType().FullName + "]");
  +                                                     
LogLog.Error("DefaultRepositorySelector: Failed to alias repository [" + 
repositoryName + "] to existing repository ["+aliasedRepository.Name+"]. 
Requested repository type ["+repositoryType.FullName+"] is not compatible with 
existing type [" + aliasedRepository.GetType().FullName + "]");
   
                                                        // We now drop through 
to create the repository without aliasing
                                                }
  @@ -362,16 +391,16 @@
                                        // If we could not find an alias
                                        if (rep == null)
                                        {
  -                                             
LogLog.Debug("DefaultRepositorySelector: Creating repository [" + repository + 
"] using type [" + repositoryType + "]");
  +                                             
LogLog.Debug("DefaultRepositorySelector: Creating repository [" + 
repositoryName + "] using type [" + repositoryType + "]");
   
                                                // Call the no arg constructor 
for the repositoryType
                                                rep = 
(ILoggerRepository)Activator.CreateInstance(repositoryType);
   
                                                // Set the name of the 
repository
  -                                             rep.Name = repository;
  +                                             rep.Name = repositoryName;
   
                                                // Store in map
  -                                             
m_name2repositoryMap[repository] = rep;
  +                                             
m_name2repositoryMap[repositoryName] = rep;
   
                                                // Notify listeners that the 
repository has been created
                                                
OnLoggerRepositoryCreatedEvent(rep);
  @@ -383,9 +412,34 @@
                }
   
                /// <summary>
  -             /// Copies the list of <see cref="ILoggerRepository"/> objects.
  +             /// Test if a named repository exists
                /// </summary>
  -             /// <returns>An array of all known <see 
cref="ILoggerRepository"/> objects.</returns>
  +             /// <param name="repositoryName">the named repository to 
check</param>
  +             /// <returns><c>true</c> if the repository exists</returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Test if a named repository exists. Use <see 
cref="CreateRepository"/>
  +             /// to create a new repository and <see cref="GetRepository"/> 
to retrieve 
  +             /// a repository.
  +             /// </para>
  +             /// </remarks>
  +             public bool ExistsRepository(string repositoryName)
  +             {
  +                     lock(this)
  +                     {
  +                             return 
m_name2repositoryMap.ContainsKey(repositoryName);
  +                     }
  +             }
  +
  +             /// <summary>
  +             /// Gets a list of <see cref="ILoggerRepository"/> objects
  +             /// </summary>
  +             /// <returns>an array of all known <see 
cref="ILoggerRepository"/> objects</returns>
  +             /// <remarks>
  +             /// <para>
  +             /// Gets an array of all of the repositories created by this 
selector.
  +             /// </para>
  +             /// </remarks>
                public ILoggerRepository[] GetAllRepositories()
                {
                        lock(this)
  @@ -470,6 +524,11 @@
                /// Notifies the registered listeners that the repository has 
been created.
                /// </summary>
                /// <param name="repository">The repository that has been 
created.</param>
  +             /// <remarks>
  +             /// <para>
  +             /// Raises the <see cref="LoggerRepositoryCreatedEvent"/> event.
  +             /// </para>
  +             /// </remarks>
                protected virtual void 
OnLoggerRepositoryCreatedEvent(ILoggerRepository repository) 
                {
                        LoggerRepositoryCreationEventHandler handler = 
m_loggerRepositoryCreatedEvent;
  @@ -670,10 +729,10 @@
   
                #region Private Instance Fields
   
  -             private IDictionary m_name2repositoryMap = new Hashtable();
  -             private IDictionary m_assembly2repositoryMap = new Hashtable();
  -             private IDictionary m_alias2repositoryMap = new Hashtable();
  -             private Type m_defaultRepositoryType;
  +             private readonly Hashtable m_name2repositoryMap = new 
Hashtable();
  +             private readonly Hashtable m_assembly2repositoryMap = new 
Hashtable();
  +             private readonly Hashtable m_alias2repositoryMap = new 
Hashtable();
  +             private readonly Type m_defaultRepositoryType;
   
                private event LoggerRepositoryCreationEventHandler 
m_loggerRepositoryCreatedEvent;
   
  
  
  

Reply via email to