SimpleLayout.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 System.Text;
  22. using log4net.Util;
  23. using log4net.Core;
  24. namespace log4net.Layout
  25. {
  26. /// <summary>
  27. /// A very simple layout
  28. /// </summary>
  29. /// <remarks>
  30. /// <para>
  31. /// SimpleLayout consists of the level of the log statement,
  32. /// followed by " - " and then the log message itself. For example,
  33. /// <code>
  34. /// DEBUG - Hello world
  35. /// </code>
  36. /// </para>
  37. /// </remarks>
  38. /// <author>Nicko Cadell</author>
  39. /// <author>Gert Driesen</author>
  40. public class SimpleLayout : LayoutSkeleton
  41. {
  42. #region Constructors
  43. /// <summary>
  44. /// Constructs a SimpleLayout
  45. /// </summary>
  46. public SimpleLayout()
  47. {
  48. IgnoresException = true;
  49. }
  50. #endregion
  51. #region Implementation of IOptionHandler
  52. /// <summary>
  53. /// Initialize layout options
  54. /// </summary>
  55. /// <remarks>
  56. /// <para>
  57. /// This is part of the <see cref="IOptionHandler"/> delayed object
  58. /// activation scheme. The <see cref="ActivateOptions"/> method must
  59. /// be called on this object after the configuration properties have
  60. /// been set. Until <see cref="ActivateOptions"/> is called this
  61. /// object is in an undefined state and must not be used.
  62. /// </para>
  63. /// <para>
  64. /// If any of the configuration properties are modified then
  65. /// <see cref="ActivateOptions"/> must be called again.
  66. /// </para>
  67. /// </remarks>
  68. override public void ActivateOptions()
  69. {
  70. // nothing to do.
  71. }
  72. #endregion
  73. #region Override implementation of LayoutSkeleton
  74. /// <summary>
  75. /// Produces a simple formatted output.
  76. /// </summary>
  77. /// <param name="loggingEvent">the event being logged</param>
  78. /// <param name="writer">The TextWriter to write the formatted event to</param>
  79. /// <remarks>
  80. /// <para>
  81. /// Formats the event as the level of the even,
  82. /// followed by " - " and then the log message itself. The
  83. /// output is terminated by a newline.
  84. /// </para>
  85. /// </remarks>
  86. override public void Format(TextWriter writer, LoggingEvent loggingEvent)
  87. {
  88. if (loggingEvent == null)
  89. {
  90. throw new ArgumentNullException("loggingEvent");
  91. }
  92. writer.Write(loggingEvent.Level.DisplayName);
  93. writer.Write(" - ");
  94. loggingEvent.WriteRenderedMessage(writer);
  95. writer.WriteLine();
  96. }
  97. #endregion
  98. }
  99. }