logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpsen...@apache.org
Subject svn commit: r1489769 - /logging/log4net/trunk/src/Appender/SmtpAppender.cs
Date Wed, 05 Jun 2013 09:28:57 GMT
Author: dpsenner
Date: Wed Jun  5 09:28:57 2013
New Revision: 1489769

URL: http://svn.apache.org/r1489769
Log:
LOG4NET-354 added a configuration option that allows to configure the subject and body encoding

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

Modified: logging/log4net/trunk/src/Appender/SmtpAppender.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Appender/SmtpAppender.cs?rev=1489769&r1=1489768&r2=1489769&view=diff
==============================================================================
--- logging/log4net/trunk/src/Appender/SmtpAppender.cs (original)
+++ logging/log4net/trunk/src/Appender/SmtpAppender.cs Wed Jun  5 09:28:57 2013
@@ -23,6 +23,7 @@
 
 using System;
 using System.IO;
+using System.Text;
 
 #if NET_2_0
 using System.Net.Mail;
@@ -349,6 +350,30 @@ namespace log4net.Appender
         }
 #endif
 
+		/// <summary>
+		/// Gets or sets the subject encoding to be used.
+		/// </summary>
+		/// <remarks>
+		/// The default encoding is the operating system's current ANSI codepage.
+		/// </remarks>
+		public Encoding SubjectEncoding
+		{
+			get { return m_subjectEncoding; }
+			set { m_subjectEncoding = value; }
+		}
+
+		/// <summary>
+		/// Gets or sets the body encoding to be used.
+		/// </summary>
+		/// <remarks>
+		/// The default encoding is the operating system's current ANSI codepage.
+		/// </remarks>
+		public Encoding BodyEncoding
+		{
+			get { return m_bodyEncoding; }
+			set { m_bodyEncoding = value; }
+		}
+
 		#endregion // Public Instance Properties
 
 		#region Override implementation of BufferingAppenderSkeleton
@@ -448,6 +473,7 @@ namespace log4net.Appender
             using (MailMessage mailMessage = new MailMessage())
             {
                 mailMessage.Body = messageBody;
+				mailMessage.BodyEncoding = m_bodyEncoding;
                 mailMessage.From = new MailAddress(m_from);
                 mailMessage.To.Add(m_to);
                 if (!String.IsNullOrEmpty(m_cc))
@@ -469,6 +495,7 @@ namespace log4net.Appender
 #endif
                 }
                 mailMessage.Subject = m_subject;
+				mailMessage.SubjectEncoding = m_subjectEncoding;
                 mailMessage.Priority = m_mailPriority;
 
                 // TODO: Consider using SendAsync to send the message without blocking. This
would be a change in
@@ -480,6 +507,7 @@ namespace log4net.Appender
 
 				MailMessage mailMessage = new MailMessage();
 				mailMessage.Body = messageBody;
+				mailMessage.BodyEncoding = m_bodyEncoding;
 				mailMessage.From = m_from;
 				mailMessage.To = m_to;
                 if (m_cc != null && m_cc.Length > 0)
@@ -491,6 +519,7 @@ namespace log4net.Appender
                     mailMessage.Bcc = m_bcc;
                 }
 				mailMessage.Subject = m_subject;
+				mailMessage.SubjectEncoding = m_subjectEncoding;
 				mailMessage.Priority = m_mailPriority;
 
 #if NET_1_1
@@ -548,7 +577,7 @@ namespace log4net.Appender
 
 				SmtpMail.Send(mailMessage);
 #endif // if NET_2_0
-        }
+		}
 
 		#endregion // Protected Methods
 
@@ -560,6 +589,8 @@ namespace log4net.Appender
 		private string m_from;
 		private string m_subject;
 		private string m_smtpHost;
+		private Encoding m_subjectEncoding = Encoding.Default;
+		private Encoding m_bodyEncoding = Encoding.Default;
 
 		// authentication fields
 		private SmtpAuthentication m_authentication = SmtpAuthentication.None;



Mime
View raw message