1 #region Copyright & License
2 //
3 // Copyright 2001-2005 The Apache Software Foundation
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 #endregion
18 
19 using System.Text;
20 
21 using log4net.Core;
22 using log4net.Appender;
23 
24 namespace log4net.Tests.Appender
25 {
26 	/// <summary>
27 	/// Write events to a string
28 	/// </summary>
29 	/// <author>Nicko Cadell</author>
30 	public class StringAppender : AppenderSkeleton
31 	{
32 		private StringBuilder m_buf = new StringBuilder();
33 
34 		/// <summary>
35 		/// Initializes a new instance of the <see cref="StringAppender" /> class.
36 		/// </summary>
StringAppender()37 		public StringAppender()
38 		{
39 		}
40 
41 		/// <summary>
42 		/// Get the string logged so far
43 		/// </summary>
44 		/// <returns></returns>
GetString()45 		public string GetString()
46 		{
47 			return m_buf.ToString();
48 		}
49 
50 		/// <summary>
51 		/// Reset the string
52 		/// </summary>
Reset()53 		public void Reset()
54 		{
55 			m_buf.Length = 0;
56 		}
57 
58 		/// <summary>
59 		/// </summary>
60 		/// <param name="loggingEvent">the event to log</param>
Append(LoggingEvent loggingEvent)61 		override protected void Append(LoggingEvent loggingEvent)
62 		{
63 			m_buf.Append(RenderLoggingEvent(loggingEvent));
64 		}
65 
66 		/// <summary>
67 		/// This appender requires a <see cref="Layout"/> to be set.
68 		/// </summary>
69 		/// <value><c>true</c></value>
70 		override protected bool RequiresLayout
71 		{
72 			get { return true; }
73 		}
74 	}
75 }
76