GlobalContext.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.Util;
  22. namespace log4net
  23. {
  24. /// <summary>
  25. /// The log4net Global Context.
  26. /// </summary>
  27. /// <remarks>
  28. /// <para>
  29. /// The <c>GlobalContext</c> provides a location for global debugging
  30. /// information to be stored.
  31. /// </para>
  32. /// <para>
  33. /// The global context has a properties map and these properties can
  34. /// be included in the output of log messages. The <see cref="log4net.Layout.PatternLayout"/>
  35. /// supports selecting and outputing these properties.
  36. /// </para>
  37. /// <para>
  38. /// By default the <c>log4net:HostName</c> property is set to the name of
  39. /// the current machine.
  40. /// </para>
  41. /// </remarks>
  42. /// <example>
  43. /// <code lang="C#">
  44. /// GlobalContext.Properties["hostname"] = Environment.MachineName;
  45. /// </code>
  46. /// </example>
  47. /// <threadsafety static="true" instance="true" />
  48. /// <author>Nicko Cadell</author>
  49. public sealed class GlobalContext
  50. {
  51. #region Private Instance Constructors
  52. /// <summary>
  53. /// Private Constructor.
  54. /// </summary>
  55. /// <remarks>
  56. /// Uses a private access modifier to prevent instantiation of this class.
  57. /// </remarks>
  58. private GlobalContext()
  59. {
  60. }
  61. #endregion Private Instance Constructors
  62. static GlobalContext()
  63. {
  64. Properties[log4net.Core.LoggingEvent.HostNameProperty] = SystemInfo.HostName;
  65. }
  66. #region Public Static Properties
  67. /// <summary>
  68. /// The global properties map.
  69. /// </summary>
  70. /// <value>
  71. /// The global properties map.
  72. /// </value>
  73. /// <remarks>
  74. /// <para>
  75. /// The global properties map.
  76. /// </para>
  77. /// </remarks>
  78. public static GlobalContextProperties Properties
  79. {
  80. get { return s_properties; }
  81. }
  82. #endregion Public Static Properties
  83. #region Private Static Fields
  84. /// <summary>
  85. /// The global context properties instance
  86. /// </summary>
  87. private readonly static GlobalContextProperties s_properties = new GlobalContextProperties();
  88. #endregion Private Static Fields
  89. }
  90. }