Layout2RawLayoutAdapter.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.IO;
  21. using log4net;
  22. using log4net.Core;
  23. namespace log4net.Layout
  24. {
  25. /// <summary>
  26. /// Adapts any <see cref="ILayout"/> to a <see cref="IRawLayout"/>
  27. /// </summary>
  28. /// <remarks>
  29. /// <para>
  30. /// Where an <see cref="IRawLayout"/> is required this adapter
  31. /// allows a <see cref="ILayout"/> to be specified.
  32. /// </para>
  33. /// </remarks>
  34. /// <author>Nicko Cadell</author>
  35. /// <author>Gert Driesen</author>
  36. public class Layout2RawLayoutAdapter : IRawLayout
  37. {
  38. #region Member Variables
  39. /// <summary>
  40. /// The layout to adapt
  41. /// </summary>
  42. private ILayout m_layout;
  43. #endregion
  44. #region Constructors
  45. /// <summary>
  46. /// Construct a new adapter
  47. /// </summary>
  48. /// <param name="layout">the layout to adapt</param>
  49. /// <remarks>
  50. /// <para>
  51. /// Create the adapter for the specified <paramref name="layout"/>.
  52. /// </para>
  53. /// </remarks>
  54. public Layout2RawLayoutAdapter(ILayout layout)
  55. {
  56. m_layout = layout;
  57. }
  58. #endregion
  59. #region Implementation of IRawLayout
  60. /// <summary>
  61. /// Format the logging event as an object.
  62. /// </summary>
  63. /// <param name="loggingEvent">The event to format</param>
  64. /// <returns>returns the formatted event</returns>
  65. /// <remarks>
  66. /// <para>
  67. /// Format the logging event as an object.
  68. /// </para>
  69. /// <para>
  70. /// Uses the <see cref="ILayout"/> object supplied to
  71. /// the constructor to perform the formatting.
  72. /// </para>
  73. /// </remarks>
  74. virtual public object Format(LoggingEvent loggingEvent)
  75. {
  76. StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
  77. m_layout.Format(writer, loggingEvent);
  78. return writer.ToString();
  79. }
  80. #endregion
  81. }
  82. }