DefaultLoggerFactory.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #region Apache License
  2. //
  3. // Licensed to the Apache Software Foundation (ASF) under one or more
  4. // contributor license agreements. See the NOTICE file distributed with
  5. // this work for additional information regarding copyright ownership.
  6. // The ASF licenses this file to you under the Apache License, Version 2.0
  7. // (the "License"); you may not use this file except in compliance with
  8. // the License. You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. #endregion
  19. using log4net.Core;
  20. namespace log4net.Repository.Hierarchy
  21. {
  22. /// <summary>
  23. /// Default implementation of <see cref="ILoggerFactory"/>
  24. /// </summary>
  25. /// <remarks>
  26. /// <para>
  27. /// This default implementation of the <see cref="ILoggerFactory"/>
  28. /// interface is used to create the default subclass
  29. /// of the <see cref="Logger"/> object.
  30. /// </para>
  31. /// </remarks>
  32. /// <author>Nicko Cadell</author>
  33. /// <author>Gert Driesen</author>
  34. internal class DefaultLoggerFactory : ILoggerFactory
  35. {
  36. #region Internal Instance Constructors
  37. /// <summary>
  38. /// Default constructor
  39. /// </summary>
  40. /// <remarks>
  41. /// <para>
  42. /// Initializes a new instance of the <see cref="DefaultLoggerFactory" /> class.
  43. /// </para>
  44. /// </remarks>
  45. internal DefaultLoggerFactory()
  46. {
  47. }
  48. #endregion Internal Instance Constructors
  49. #region Implementation of ILoggerFactory
  50. /// <summary>
  51. /// Create a new <see cref="Logger" /> instance
  52. /// </summary>
  53. /// <param name="repository">The <see cref="ILoggerRepository" /> that will own the <see cref="Logger" />.</param>
  54. /// <param name="name">The name of the <see cref="Logger" />.</param>
  55. /// <returns>The <see cref="Logger" /> instance for the specified name.</returns>
  56. /// <remarks>
  57. /// <para>
  58. /// Create a new <see cref="Logger" /> instance with the
  59. /// specified name.
  60. /// </para>
  61. /// <para>
  62. /// Called by the <see cref="Hierarchy"/> to create
  63. /// new named <see cref="Logger"/> instances.
  64. /// </para>
  65. /// <para>
  66. /// If the <paramref name="name"/> is <c>null</c> then the root logger
  67. /// must be returned.
  68. /// </para>
  69. /// </remarks>
  70. public Logger CreateLogger(ILoggerRepository repository, string name)
  71. {
  72. if (name == null)
  73. {
  74. return new RootLogger(repository.LevelMap.LookupWithDefault(Level.Debug));
  75. }
  76. return new LoggerImpl(name);
  77. }
  78. #endregion
  79. /// <summary>
  80. /// Default internal subclass of <see cref="Logger"/>
  81. /// </summary>
  82. /// <remarks>
  83. /// <para>
  84. /// This subclass has no additional behavior over the
  85. /// <see cref="Logger"/> class but does allow instances
  86. /// to be created.
  87. /// </para>
  88. /// </remarks>
  89. internal sealed class LoggerImpl : Logger
  90. {
  91. /// <summary>
  92. /// Construct a new Logger
  93. /// </summary>
  94. /// <param name="name">the name of the logger</param>
  95. /// <remarks>
  96. /// <para>
  97. /// Initializes a new instance of the <see cref="LoggerImpl" /> class
  98. /// with the specified name.
  99. /// </para>
  100. /// </remarks>
  101. internal LoggerImpl(string name) : base(name)
  102. {
  103. }
  104. }
  105. }
  106. }