DOMConfigurator.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.Xml;
  21. using System.Collections;
  22. using System.IO;
  23. using System.Reflection;
  24. using System.Threading;
  25. using log4net.Appender;
  26. using log4net.Util;
  27. using log4net.Repository;
  28. namespace log4net.Config
  29. {
  30. /// <summary>
  31. /// Use this class to initialize the log4net environment using an Xml tree.
  32. /// </summary>
  33. /// <remarks>
  34. /// <para>
  35. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  36. /// </para>
  37. /// <para>
  38. /// Configures a <see cref="ILoggerRepository"/> using an Xml tree.
  39. /// </para>
  40. /// </remarks>
  41. /// <author>Nicko Cadell</author>
  42. /// <author>Gert Driesen</author>
  43. [Obsolete("Use XmlConfigurator instead of DOMConfigurator")]
  44. public sealed class DOMConfigurator
  45. {
  46. #region Private Instance Constructors
  47. /// <summary>
  48. /// Private constructor
  49. /// </summary>
  50. private DOMConfigurator()
  51. {
  52. }
  53. #endregion Protected Instance Constructors
  54. #region Configure static methods
  55. /// <summary>
  56. /// Automatically configures the log4net system based on the
  57. /// application's configuration settings.
  58. /// </summary>
  59. /// <remarks>
  60. /// <para>
  61. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  62. /// </para>
  63. /// Each application has a configuration file. This has the
  64. /// same name as the application with '.config' appended.
  65. /// This file is XML and calling this function prompts the
  66. /// configurator to look in that file for a section called
  67. /// <c>log4net</c> that contains the configuration data.
  68. /// </remarks>
  69. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  70. static public void Configure()
  71. {
  72. XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()));
  73. }
  74. /// <summary>
  75. /// Automatically configures the <see cref="ILoggerRepository"/> using settings
  76. /// stored in the application's configuration file.
  77. /// </summary>
  78. /// <remarks>
  79. /// <para>
  80. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  81. /// </para>
  82. /// Each application has a configuration file. This has the
  83. /// same name as the application with '.config' appended.
  84. /// This file is XML and calling this function prompts the
  85. /// configurator to look in that file for a section called
  86. /// <c>log4net</c> that contains the configuration data.
  87. /// </remarks>
  88. /// <param name="repository">The repository to configure.</param>
  89. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  90. static public void Configure(ILoggerRepository repository)
  91. {
  92. XmlConfigurator.Configure(repository);
  93. }
  94. /// <summary>
  95. /// Configures log4net using a <c>log4net</c> element
  96. /// </summary>
  97. /// <remarks>
  98. /// <para>
  99. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  100. /// </para>
  101. /// Loads the log4net configuration from the XML element
  102. /// supplied as <paramref name="element"/>.
  103. /// </remarks>
  104. /// <param name="element">The element to parse.</param>
  105. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  106. static public void Configure(XmlElement element)
  107. {
  108. XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), element);
  109. }
  110. /// <summary>
  111. /// Configures the <see cref="ILoggerRepository"/> using the specified XML
  112. /// element.
  113. /// </summary>
  114. /// <remarks>
  115. /// <para>
  116. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  117. /// </para>
  118. /// Loads the log4net configuration from the XML element
  119. /// supplied as <paramref name="element"/>.
  120. /// </remarks>
  121. /// <param name="repository">The repository to configure.</param>
  122. /// <param name="element">The element to parse.</param>
  123. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  124. static public void Configure(ILoggerRepository repository, XmlElement element)
  125. {
  126. XmlConfigurator.Configure(repository, element);
  127. }
  128. /// <summary>
  129. /// Configures log4net using the specified configuration file.
  130. /// </summary>
  131. /// <param name="configFile">The XML file to load the configuration from.</param>
  132. /// <remarks>
  133. /// <para>
  134. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  135. /// </para>
  136. /// <para>
  137. /// The configuration file must be valid XML. It must contain
  138. /// at least one element called <c>log4net</c> that holds
  139. /// the log4net configuration data.
  140. /// </para>
  141. /// <para>
  142. /// The log4net configuration file can possible be specified in the application's
  143. /// configuration file (either <c>MyAppName.exe.config</c> for a
  144. /// normal application on <c>Web.config</c> for an ASP.NET application).
  145. /// </para>
  146. /// <example>
  147. /// The following example configures log4net using a configuration file, of which the
  148. /// location is stored in the application's configuration file :
  149. /// </example>
  150. /// <code lang="C#">
  151. /// using log4net.Config;
  152. /// using System.IO;
  153. /// using System.Configuration;
  154. ///
  155. /// ...
  156. ///
  157. /// DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
  158. /// </code>
  159. /// <para>
  160. /// In the <c>.config</c> file, the path to the log4net can be specified like this :
  161. /// </para>
  162. /// <code lang="XML" escaped="true">
  163. /// <configuration>
  164. /// <appSettings>
  165. /// <add key="log4net-config-file" value="log.config"/>
  166. /// </appSettings>
  167. /// </configuration>
  168. /// </code>
  169. /// </remarks>
  170. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  171. static public void Configure(FileInfo configFile)
  172. {
  173. XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configFile);
  174. }
  175. /// <summary>
  176. /// Configures log4net using the specified configuration file.
  177. /// </summary>
  178. /// <param name="configStream">A stream to load the XML configuration from.</param>
  179. /// <remarks>
  180. /// <para>
  181. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  182. /// </para>
  183. /// <para>
  184. /// The configuration data must be valid XML. It must contain
  185. /// at least one element called <c>log4net</c> that holds
  186. /// the log4net configuration data.
  187. /// </para>
  188. /// <para>
  189. /// Note that this method will NOT close the stream parameter.
  190. /// </para>
  191. /// </remarks>
  192. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  193. static public void Configure(Stream configStream)
  194. {
  195. XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configStream);
  196. }
  197. /// <summary>
  198. /// Configures the <see cref="ILoggerRepository"/> using the specified configuration
  199. /// file.
  200. /// </summary>
  201. /// <param name="repository">The repository to configure.</param>
  202. /// <param name="configFile">The XML file to load the configuration from.</param>
  203. /// <remarks>
  204. /// <para>
  205. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  206. /// </para>
  207. /// <para>
  208. /// The configuration file must be valid XML. It must contain
  209. /// at least one element called <c>log4net</c> that holds
  210. /// the configuration data.
  211. /// </para>
  212. /// <para>
  213. /// The log4net configuration file can possible be specified in the application's
  214. /// configuration file (either <c>MyAppName.exe.config</c> for a
  215. /// normal application on <c>Web.config</c> for an ASP.NET application).
  216. /// </para>
  217. /// <example>
  218. /// The following example configures log4net using a configuration file, of which the
  219. /// location is stored in the application's configuration file :
  220. /// </example>
  221. /// <code lang="C#">
  222. /// using log4net.Config;
  223. /// using System.IO;
  224. /// using System.Configuration;
  225. ///
  226. /// ...
  227. ///
  228. /// DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
  229. /// </code>
  230. /// <para>
  231. /// In the <c>.config</c> file, the path to the log4net can be specified like this :
  232. /// </para>
  233. /// <code lang="XML" escaped="true">
  234. /// <configuration>
  235. /// <appSettings>
  236. /// <add key="log4net-config-file" value="log.config"/>
  237. /// </appSettings>
  238. /// </configuration>
  239. /// </code>
  240. /// </remarks>
  241. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  242. static public void Configure(ILoggerRepository repository, FileInfo configFile)
  243. {
  244. XmlConfigurator.Configure(repository, configFile);
  245. }
  246. /// <summary>
  247. /// Configures the <see cref="ILoggerRepository"/> using the specified configuration
  248. /// file.
  249. /// </summary>
  250. /// <param name="repository">The repository to configure.</param>
  251. /// <param name="configStream">The stream to load the XML configuration from.</param>
  252. /// <remarks>
  253. /// <para>
  254. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  255. /// </para>
  256. /// <para>
  257. /// The configuration data must be valid XML. It must contain
  258. /// at least one element called <c>log4net</c> that holds
  259. /// the configuration data.
  260. /// </para>
  261. /// <para>
  262. /// Note that this method will NOT close the stream parameter.
  263. /// </para>
  264. /// </remarks>
  265. [Obsolete("Use XmlConfigurator.Configure instead of DOMConfigurator.Configure")]
  266. static public void Configure(ILoggerRepository repository, Stream configStream)
  267. {
  268. XmlConfigurator.Configure(repository, configStream);
  269. }
  270. #endregion Configure static methods
  271. #region ConfigureAndWatch static methods
  272. #if (!NETCF && !SSCLI)
  273. /// <summary>
  274. /// Configures log4net using the file specified, monitors the file for changes
  275. /// and reloads the configuration if a change is detected.
  276. /// </summary>
  277. /// <param name="configFile">The XML file to load the configuration from.</param>
  278. /// <remarks>
  279. /// <para>
  280. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  281. /// </para>
  282. /// <para>
  283. /// The configuration file must be valid XML. It must contain
  284. /// at least one element called <c>log4net</c> that holds
  285. /// the configuration data.
  286. /// </para>
  287. /// <para>
  288. /// The configuration file will be monitored using a <see cref="FileSystemWatcher"/>
  289. /// and depends on the behavior of that class.
  290. /// </para>
  291. /// <para>
  292. /// For more information on how to configure log4net using
  293. /// a separate configuration file, see <see cref="M:Configure(FileInfo)"/>.
  294. /// </para>
  295. /// </remarks>
  296. /// <seealso cref="M:Configure(FileInfo)"/>
  297. [Obsolete("Use XmlConfigurator.ConfigureAndWatch instead of DOMConfigurator.ConfigureAndWatch")]
  298. static public void ConfigureAndWatch(FileInfo configFile)
  299. {
  300. XmlConfigurator.ConfigureAndWatch(LogManager.GetRepository(Assembly.GetCallingAssembly()), configFile);
  301. }
  302. /// <summary>
  303. /// Configures the <see cref="ILoggerRepository"/> using the file specified,
  304. /// monitors the file for changes and reloads the configuration if a change
  305. /// is detected.
  306. /// </summary>
  307. /// <param name="repository">The repository to configure.</param>
  308. /// <param name="configFile">The XML file to load the configuration from.</param>
  309. /// <remarks>
  310. /// <para>
  311. /// <b>DOMConfigurator is obsolete. Use XmlConfigurator instead of DOMConfigurator.</b>
  312. /// </para>
  313. /// <para>
  314. /// The configuration file must be valid XML. It must contain
  315. /// at least one element called <c>log4net</c> that holds
  316. /// the configuration data.
  317. /// </para>
  318. /// <para>
  319. /// The configuration file will be monitored using a <see cref="FileSystemWatcher"/>
  320. /// and depends on the behavior of that class.
  321. /// </para>
  322. /// <para>
  323. /// For more information on how to configure log4net using
  324. /// a separate configuration file, see <see cref="M:Configure(FileInfo)"/>.
  325. /// </para>
  326. /// </remarks>
  327. /// <seealso cref="M:Configure(FileInfo)"/>
  328. [Obsolete("Use XmlConfigurator.ConfigureAndWatch instead of DOMConfigurator.ConfigureAndWatch")]
  329. static public void ConfigureAndWatch(ILoggerRepository repository, FileInfo configFile)
  330. {
  331. XmlConfigurator.ConfigureAndWatch(repository, configFile);
  332. }
  333. #endif
  334. #endregion ConfigureAndWatch static methods
  335. }
  336. }