RawPropertyLayout.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.Text;
  21. using log4net.Core;
  22. using log4net.Util;
  23. namespace log4net.Layout
  24. {
  25. /// <summary>
  26. /// Extract the value of a property from the <see cref="LoggingEvent"/>
  27. /// </summary>
  28. /// <remarks>
  29. /// <para>
  30. /// Extract the value of a property from the <see cref="LoggingEvent"/>
  31. /// </para>
  32. /// </remarks>
  33. /// <author>Nicko Cadell</author>
  34. public class RawPropertyLayout : IRawLayout
  35. {
  36. #region Constructors
  37. /// <summary>
  38. /// Constructs a RawPropertyLayout
  39. /// </summary>
  40. public RawPropertyLayout()
  41. {
  42. }
  43. #endregion
  44. private string m_key;
  45. /// <summary>
  46. /// The name of the value to lookup in the LoggingEvent Properties collection.
  47. /// </summary>
  48. /// <value>
  49. /// Value to lookup in the LoggingEvent Properties collection
  50. /// </value>
  51. /// <remarks>
  52. /// <para>
  53. /// String name of the property to lookup in the <see cref="LoggingEvent"/>.
  54. /// </para>
  55. /// </remarks>
  56. public string Key
  57. {
  58. get { return m_key; }
  59. set { m_key = value; }
  60. }
  61. #region Implementation of IRawLayout
  62. /// <summary>
  63. /// Lookup the property for <see cref="Key"/>
  64. /// </summary>
  65. /// <param name="loggingEvent">The event to format</param>
  66. /// <returns>returns property value</returns>
  67. /// <remarks>
  68. /// <para>
  69. /// Looks up and returns the object value of the property
  70. /// named <see cref="Key"/>. If there is no property defined
  71. /// with than name then <c>null</c> will be returned.
  72. /// </para>
  73. /// </remarks>
  74. public virtual object Format(LoggingEvent loggingEvent)
  75. {
  76. return loggingEvent.LookupProperty(m_key);
  77. }
  78. #endregion
  79. }
  80. }