123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- #region Apache License
- #endregion
- using System;
- using System.Text;
- using System.IO;
- using log4net.Layout;
- using log4net.Core;
- using log4net.Util;
- namespace log4net.Appender
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class SmtpPickupDirAppender : BufferingAppenderSkeleton
- {
- #region Public Instance Constructors
-
-
-
-
-
-
-
-
- public SmtpPickupDirAppender()
- {
- m_fileExtension = string.Empty;
- }
- #endregion Public Instance Constructors
- #region Public Instance Properties
-
-
-
-
-
-
-
-
-
-
-
- public string To
- {
- get { return m_to; }
- set { m_to = value; }
- }
-
-
-
-
-
-
-
-
-
-
-
- public string From
- {
- get { return m_from; }
- set { m_from = value; }
- }
-
-
-
-
-
-
-
-
-
-
-
- public string Subject
- {
- get { return m_subject; }
- set { m_subject = value; }
- }
-
-
-
-
-
-
-
-
-
-
- public string PickupDir
- {
- get { return m_pickupDir; }
- set { m_pickupDir = value; }
- }
-
-
-
-
-
-
-
-
-
-
-
- public string FileExtension
- {
- get { return m_fileExtension; }
- set
- {
- m_fileExtension = value;
- if (m_fileExtension == null)
- {
- m_fileExtension = string.Empty;
- }
-
- #if NET_2_0 || MONO_2_0
- if (!string.IsNullOrEmpty(m_fileExtension) && !m_fileExtension.StartsWith("."))
- #else
- if (m_fileExtension != null && m_fileExtension.Length > 0 && !m_fileExtension.StartsWith("."))
- #endif
- {
- m_fileExtension = "." + m_fileExtension;
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public SecurityContext SecurityContext
- {
- get { return m_securityContext; }
- set { m_securityContext = value; }
- }
- #endregion Public Instance Properties
- #region Override implementation of BufferingAppenderSkeleton
-
-
-
-
-
-
-
-
-
- override protected void SendBuffer(LoggingEvent[] events)
- {
-
-
- try
- {
- string filePath = null;
- StreamWriter writer = null;
-
- using(SecurityContext.Impersonate(this))
- {
- filePath = Path.Combine(m_pickupDir, SystemInfo.NewGuid().ToString("N") + m_fileExtension);
- writer = File.CreateText(filePath);
- }
- if (writer == null)
- {
- ErrorHandler.Error("Failed to create output file for writing ["+filePath+"]", null, ErrorCode.FileOpenFailure);
- }
- else
- {
- using(writer)
- {
- writer.WriteLine("To: " + m_to);
- writer.WriteLine("From: " + m_from);
- writer.WriteLine("Subject: " + m_subject);
- writer.WriteLine("Date: " + DateTime.UtcNow.ToString("r"));
- writer.WriteLine("");
- string t = Layout.Header;
- if (t != null)
- {
- writer.Write(t);
- }
- for(int i = 0; i < events.Length; i++)
- {
-
- RenderLoggingEvent(writer, events[i]);
- }
- t = Layout.Footer;
- if (t != null)
- {
- writer.Write(t);
- }
- writer.WriteLine("");
- writer.WriteLine(".");
- }
- }
- }
- catch(Exception e)
- {
- ErrorHandler.Error("Error occurred while sending e-mail notification.", e);
- }
- }
- #endregion Override implementation of BufferingAppenderSkeleton
- #region Override implementation of AppenderSkeleton
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- override public void ActivateOptions()
- {
- base.ActivateOptions();
- if (m_securityContext == null)
- {
- m_securityContext = SecurityContextProvider.DefaultProvider.CreateSecurityContext(this);
- }
- using(SecurityContext.Impersonate(this))
- {
- m_pickupDir = ConvertToFullPath(m_pickupDir.Trim());
- }
- }
-
-
-
-
-
-
-
-
-
- override protected bool RequiresLayout
- {
- get { return true; }
- }
- #endregion Override implementation of AppenderSkeleton
- #region Protected Static Methods
-
-
-
-
-
-
-
-
-
-
-
-
-
- protected static string ConvertToFullPath(string path)
- {
- return SystemInfo.ConvertToFullPath(path);
- }
- #endregion Protected Static Methods
- #region Private Instance Fields
- private string m_to;
- private string m_from;
- private string m_subject;
- private string m_pickupDir;
- private string m_fileExtension;
-
-
-
- private SecurityContext m_securityContext;
- #endregion Private Instance Fields
- }
- }
|