ILoggerRepository.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 System;
  20. using System.Collections;
  21. using log4net;
  22. using log4net.ObjectRenderer;
  23. using log4net.Core;
  24. using log4net.Plugin;
  25. using log4net.Repository.Hierarchy;
  26. using log4net.Util;
  27. namespace log4net.Repository
  28. {
  29. #region LoggerRepositoryShutdownEvent
  30. /// <summary>
  31. /// Delegate used to handle logger repository shutdown event notifications
  32. /// </summary>
  33. /// <param name="sender">The <see cref="ILoggerRepository"/> that is shutting down.</param>
  34. /// <param name="e">Empty event args</param>
  35. /// <remarks>
  36. /// <para>
  37. /// Delegate used to handle logger repository shutdown event notifications.
  38. /// </para>
  39. /// </remarks>
  40. public delegate void LoggerRepositoryShutdownEventHandler(object sender, EventArgs e);
  41. #endregion
  42. #region LoggerRepositoryConfigurationResetEventHandler
  43. /// <summary>
  44. /// Delegate used to handle logger repository configuration reset event notifications
  45. /// </summary>
  46. /// <param name="sender">The <see cref="ILoggerRepository"/> that has had its configuration reset.</param>
  47. /// <param name="e">Empty event args</param>
  48. /// <remarks>
  49. /// <para>
  50. /// Delegate used to handle logger repository configuration reset event notifications.
  51. /// </para>
  52. /// </remarks>
  53. public delegate void LoggerRepositoryConfigurationResetEventHandler(object sender, EventArgs e);
  54. #endregion
  55. #region LoggerRepositoryConfigurationChangedEventHandler
  56. /// <summary>
  57. /// Delegate used to handle event notifications for logger repository configuration changes.
  58. /// </summary>
  59. /// <param name="sender">The <see cref="ILoggerRepository"/> that has had its configuration changed.</param>
  60. /// <param name="e">Empty event arguments.</param>
  61. /// <remarks>
  62. /// <para>
  63. /// Delegate used to handle event notifications for logger repository configuration changes.
  64. /// </para>
  65. /// </remarks>
  66. public delegate void LoggerRepositoryConfigurationChangedEventHandler(object sender, EventArgs e);
  67. #endregion
  68. /// <summary>
  69. /// Interface implemented by logger repositories.
  70. /// </summary>
  71. /// <remarks>
  72. /// <para>
  73. /// This interface is implemented by logger repositories. e.g.
  74. /// <see cref="Hierarchy"/>.
  75. /// </para>
  76. /// <para>
  77. /// This interface is used by the <see cref="LogManager"/>
  78. /// to obtain <see cref="ILog"/> interfaces.
  79. /// </para>
  80. /// </remarks>
  81. /// <author>Nicko Cadell</author>
  82. /// <author>Gert Driesen</author>
  83. public interface ILoggerRepository
  84. {
  85. /// <summary>
  86. /// The name of the repository
  87. /// </summary>
  88. /// <value>
  89. /// The name of the repository
  90. /// </value>
  91. /// <remarks>
  92. /// <para>
  93. /// The name of the repository.
  94. /// </para>
  95. /// </remarks>
  96. string Name { get; set; }
  97. /// <summary>
  98. /// RendererMap accesses the object renderer map for this repository.
  99. /// </summary>
  100. /// <value>
  101. /// RendererMap accesses the object renderer map for this repository.
  102. /// </value>
  103. /// <remarks>
  104. /// <para>
  105. /// RendererMap accesses the object renderer map for this repository.
  106. /// </para>
  107. /// <para>
  108. /// The RendererMap holds a mapping between types and
  109. /// <see cref="IObjectRenderer"/> objects.
  110. /// </para>
  111. /// </remarks>
  112. RendererMap RendererMap { get; }
  113. /// <summary>
  114. /// The plugin map for this repository.
  115. /// </summary>
  116. /// <value>
  117. /// The plugin map for this repository.
  118. /// </value>
  119. /// <remarks>
  120. /// <para>
  121. /// The plugin map holds the <see cref="IPlugin"/> instances
  122. /// that have been attached to this repository.
  123. /// </para>
  124. /// </remarks>
  125. PluginMap PluginMap { get; }
  126. /// <summary>
  127. /// Get the level map for the Repository.
  128. /// </summary>
  129. /// <remarks>
  130. /// <para>
  131. /// Get the level map for the Repository.
  132. /// </para>
  133. /// <para>
  134. /// The level map defines the mappings between
  135. /// level names and <see cref="Level"/> objects in
  136. /// this repository.
  137. /// </para>
  138. /// </remarks>
  139. LevelMap LevelMap { get; }
  140. /// <summary>
  141. /// The threshold for all events in this repository
  142. /// </summary>
  143. /// <value>
  144. /// The threshold for all events in this repository
  145. /// </value>
  146. /// <remarks>
  147. /// <para>
  148. /// The threshold for all events in this repository.
  149. /// </para>
  150. /// </remarks>
  151. Level Threshold { get; set; }
  152. /// <summary>
  153. /// Check if the named logger exists in the repository. If so return
  154. /// its reference, otherwise returns <c>null</c>.
  155. /// </summary>
  156. /// <param name="name">The name of the logger to lookup</param>
  157. /// <returns>The Logger object with the name specified</returns>
  158. /// <remarks>
  159. /// <para>
  160. /// If the names logger exists it is returned, otherwise
  161. /// <c>null</c> is returned.
  162. /// </para>
  163. /// </remarks>
  164. ILogger Exists(string name);
  165. /// <summary>
  166. /// Returns all the currently defined loggers as an Array.
  167. /// </summary>
  168. /// <returns>All the defined loggers</returns>
  169. /// <remarks>
  170. /// <para>
  171. /// Returns all the currently defined loggers as an Array.
  172. /// </para>
  173. /// </remarks>
  174. ILogger[] GetCurrentLoggers();
  175. /// <summary>
  176. /// Returns a named logger instance
  177. /// </summary>
  178. /// <param name="name">The name of the logger to retrieve</param>
  179. /// <returns>The logger object with the name specified</returns>
  180. /// <remarks>
  181. /// <para>
  182. /// Returns a named logger instance.
  183. /// </para>
  184. /// <para>
  185. /// If a logger of that name already exists, then it will be
  186. /// returned. Otherwise, a new logger will be instantiated and
  187. /// then linked with its existing ancestors as well as children.
  188. /// </para>
  189. /// </remarks>
  190. ILogger GetLogger(string name);
  191. /// <summary>Shutdown the repository</summary>
  192. /// <remarks>
  193. /// <para>
  194. /// Shutting down a repository will <i>safely</i> close and remove
  195. /// all appenders in all loggers including the root logger.
  196. /// </para>
  197. /// <para>
  198. /// Some appenders need to be closed before the
  199. /// application exists. Otherwise, pending logging events might be
  200. /// lost.
  201. /// </para>
  202. /// <para>
  203. /// The <see cref="M:Shutdown()"/> method is careful to close nested
  204. /// appenders before closing regular appenders. This is allows
  205. /// configurations where a regular appender is attached to a logger
  206. /// and again to a nested appender.
  207. /// </para>
  208. /// </remarks>
  209. void Shutdown();
  210. /// <summary>
  211. /// Reset the repositories configuration to a default state
  212. /// </summary>
  213. /// <remarks>
  214. /// <para>
  215. /// Reset all values contained in this instance to their
  216. /// default state.
  217. /// </para>
  218. /// <para>
  219. /// Existing loggers are not removed. They are just reset.
  220. /// </para>
  221. /// <para>
  222. /// This method should be used sparingly and with care as it will
  223. /// block all logging until it is completed.
  224. /// </para>
  225. /// </remarks>
  226. void ResetConfiguration();
  227. /// <summary>
  228. /// Log the <see cref="LoggingEvent"/> through this repository.
  229. /// </summary>
  230. /// <param name="logEvent">the event to log</param>
  231. /// <remarks>
  232. /// <para>
  233. /// This method should not normally be used to log.
  234. /// The <see cref="ILog"/> interface should be used
  235. /// for routine logging. This interface can be obtained
  236. /// using the <see cref="M:log4net.LogManager.GetLogger(string)"/> method.
  237. /// </para>
  238. /// <para>
  239. /// The <c>logEvent</c> is delivered to the appropriate logger and
  240. /// that logger is then responsible for logging the event.
  241. /// </para>
  242. /// </remarks>
  243. void Log(LoggingEvent logEvent);
  244. /// <summary>
  245. /// Flag indicates if this repository has been configured.
  246. /// </summary>
  247. /// <value>
  248. /// Flag indicates if this repository has been configured.
  249. /// </value>
  250. /// <remarks>
  251. /// <para>
  252. /// Flag indicates if this repository has been configured.
  253. /// </para>
  254. /// </remarks>
  255. bool Configured { get; set; }
  256. /// <summary>
  257. /// Collection of internal messages captured during the most
  258. /// recent configuration process.
  259. /// </summary>
  260. ICollection ConfigurationMessages { get; set; }
  261. /// <summary>
  262. /// Event to notify that the repository has been shutdown.
  263. /// </summary>
  264. /// <value>
  265. /// Event to notify that the repository has been shutdown.
  266. /// </value>
  267. /// <remarks>
  268. /// <para>
  269. /// Event raised when the repository has been shutdown.
  270. /// </para>
  271. /// </remarks>
  272. event LoggerRepositoryShutdownEventHandler ShutdownEvent;
  273. /// <summary>
  274. /// Event to notify that the repository has had its configuration reset.
  275. /// </summary>
  276. /// <value>
  277. /// Event to notify that the repository has had its configuration reset.
  278. /// </value>
  279. /// <remarks>
  280. /// <para>
  281. /// Event raised when the repository's configuration has been
  282. /// reset to default.
  283. /// </para>
  284. /// </remarks>
  285. event LoggerRepositoryConfigurationResetEventHandler ConfigurationReset;
  286. /// <summary>
  287. /// Event to notify that the repository has had its configuration changed.
  288. /// </summary>
  289. /// <value>
  290. /// Event to notify that the repository has had its configuration changed.
  291. /// </value>
  292. /// <remarks>
  293. /// <para>
  294. /// Event raised when the repository's configuration has been changed.
  295. /// </para>
  296. /// </remarks>
  297. event LoggerRepositoryConfigurationChangedEventHandler ConfigurationChanged;
  298. /// <summary>
  299. /// Repository specific properties
  300. /// </summary>
  301. /// <value>
  302. /// Repository specific properties
  303. /// </value>
  304. /// <remarks>
  305. /// <para>
  306. /// These properties can be specified on a repository specific basis.
  307. /// </para>
  308. /// </remarks>
  309. PropertiesDictionary Properties { get; }
  310. /// <summary>
  311. /// Returns all the Appenders that are configured as an Array.
  312. /// </summary>
  313. /// <returns>All the Appenders</returns>
  314. /// <remarks>
  315. /// <para>
  316. /// Returns all the Appenders that are configured as an Array.
  317. /// </para>
  318. /// </remarks>
  319. log4net.Appender.IAppender[] GetAppenders();
  320. }
  321. }