ILayout.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /// Interface implemented by layout objects
  27. /// </summary>
  28. /// <remarks>
  29. /// <para>
  30. /// An <see cref="ILayout"/> object is used to format a <see cref="LoggingEvent"/>
  31. /// as text. The <see cref="M:Format(TextWriter,LoggingEvent)"/> method is called by an
  32. /// appender to transform the <see cref="LoggingEvent"/> into a string.
  33. /// </para>
  34. /// <para>
  35. /// The layout can also supply <see cref="Header"/> and <see cref="Footer"/>
  36. /// text that is appender before any events and after all the events respectively.
  37. /// </para>
  38. /// </remarks>
  39. /// <author>Nicko Cadell</author>
  40. /// <author>Gert Driesen</author>
  41. public interface ILayout
  42. {
  43. /// <summary>
  44. /// Implement this method to create your own layout format.
  45. /// </summary>
  46. /// <param name="writer">The TextWriter to write the formatted event to</param>
  47. /// <param name="loggingEvent">The event to format</param>
  48. /// <remarks>
  49. /// <para>
  50. /// This method is called by an appender to format
  51. /// the <paramref name="loggingEvent"/> as text and output to a writer.
  52. /// </para>
  53. /// <para>
  54. /// If the caller does not have a <see cref="TextWriter"/> and prefers the
  55. /// event to be formatted as a <see cref="String"/> then the following
  56. /// code can be used to format the event into a <see cref="StringWriter"/>.
  57. /// </para>
  58. /// <code lang="C#">
  59. /// StringWriter writer = new StringWriter();
  60. /// Layout.Format(writer, loggingEvent);
  61. /// string formattedEvent = writer.ToString();
  62. /// </code>
  63. /// </remarks>
  64. void Format(TextWriter writer, LoggingEvent loggingEvent);
  65. /// <summary>
  66. /// The content type output by this layout.
  67. /// </summary>
  68. /// <value>The content type</value>
  69. /// <remarks>
  70. /// <para>
  71. /// The content type output by this layout.
  72. /// </para>
  73. /// <para>
  74. /// This is a MIME type e.g. <c>"text/plain"</c>.
  75. /// </para>
  76. /// </remarks>
  77. string ContentType { get; }
  78. /// <summary>
  79. /// The header for the layout format.
  80. /// </summary>
  81. /// <value>the layout header</value>
  82. /// <remarks>
  83. /// <para>
  84. /// The Header text will be appended before any logging events
  85. /// are formatted and appended.
  86. /// </para>
  87. /// </remarks>
  88. string Header { get; }
  89. /// <summary>
  90. /// The footer for the layout format.
  91. /// </summary>
  92. /// <value>the layout footer</value>
  93. /// <remarks>
  94. /// <para>
  95. /// The Footer text will be appended after all the logging events
  96. /// have been formatted and appended.
  97. /// </para>
  98. /// </remarks>
  99. string Footer { get; }
  100. /// <summary>
  101. /// Flag indicating if this layout handle exceptions
  102. /// </summary>
  103. /// <value><c>false</c> if this layout handles exceptions</value>
  104. /// <remarks>
  105. /// <para>
  106. /// If this layout handles the exception object contained within
  107. /// <see cref="LoggingEvent"/>, then the layout should return
  108. /// <c>false</c>. Otherwise, if the layout ignores the exception
  109. /// object, then the layout should return <c>true</c>.
  110. /// </para>
  111. /// </remarks>
  112. bool IgnoresException { get; }
  113. }
  114. }