You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by bo...@apache.org on 2015/04/05 16:04:40 UTC

svn commit: r1671398 - /logging/log4net/trunk/src/log4net/Appender/SmtpAppender.cs

Author: bodewig
Date: Sun Apr  5 14:04:40 2015
New Revision: 1671398

URL: http://svn.apache.org/r1671398
Log:
extract method that creates the SMTP message's body

Modified:
    logging/log4net/trunk/src/log4net/Appender/SmtpAppender.cs

Modified: logging/log4net/trunk/src/log4net/Appender/SmtpAppender.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net/Appender/SmtpAppender.cs?rev=1671398&r1=1671397&r2=1671398&view=diff
==============================================================================
--- logging/log4net/trunk/src/log4net/Appender/SmtpAppender.cs (original)
+++ logging/log4net/trunk/src/log4net/Appender/SmtpAppender.cs Sun Apr  5 14:04:40 2015
@@ -312,39 +312,19 @@ namespace log4net.Appender
 		/// Sends the contents of the cyclic buffer as an e-mail message.
 		/// </summary>
 		/// <param name="events">The logging events to send.</param>
-		override protected void SendBuffer(LoggingEvent[] events) 
-		{
-			// Note: this code already owns the monitor for this
-			// appender. This frees us from needing to synchronize again.
-			try 
-			{	  
-				StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
-
-				string t = Layout.Header;
-				if (t != null)
-				{
-					writer.Write(t);
-				}
-
-				for(int i = 0; i < events.Length; i++) 
-				{
-					// Render the event and append the text to the buffer
-					RenderLoggingEvent(writer, events[i]);
-				}
-
-				t = Layout.Footer;
-				if (t != null)
-				{
-					writer.Write(t);
-				}
-
-				SendEmail(writer.ToString());
-			} 
-			catch(Exception e) 
-			{
-				ErrorHandler.Error("Error occurred while sending e-mail notification.", e);
-			}
-		}
+        override protected void SendBuffer(LoggingEvent[] events)
+        {
+            // Note: this code already owns the monitor for this
+            // appender. This frees us from needing to synchronize again.
+            try
+            {
+                SendEmail(GetMailMessageBody(events));
+            }
+            catch (Exception e)
+            {
+                ErrorHandler.Error("Error occurred while sending e-mail notification.", e);
+            }
+        }
 
 		#endregion // Override implementation of BufferingAppenderSkeleton
 
@@ -368,7 +348,37 @@ namespace log4net.Appender
 
 		#region Protected Methods
 
-		/// <summary>
+        /// <summary>
+        /// Creates the body of the message to send
+        /// </summary>
+        /// <param name="events"></param>
+        /// <returns></returns>
+        virtual protected string GetMailMessageBody(LoggingEvent[] events)
+        {
+            StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
+
+            string t = Layout.Header;
+            if (t != null)
+            {
+                writer.Write(t);
+            }
+
+            for (int i = 0; i < events.Length; i++)
+            {
+                // Render the event and append the text to the buffer
+                RenderLoggingEvent(writer, events[i]);
+            }
+
+            t = Layout.Footer;
+            if (t != null)
+            {
+                writer.Write(t);
+            }
+
+            return writer.ToString();
+        }
+        
+        /// <summary>
 		/// Send the email message
 		/// </summary>
 		/// <param name="messageBody">the body text to include in the mail</param>