/// <summary> /// Initializes a <see cref="EmailMessage"/> with the raw data to create and email, a message, and the formatter /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="message">Represents the message to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> public EmailMessage(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, string message, ILogFormatter formatter) { this.configurationData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty); this.logEntry = new LogEntry(); logEntry.Message = message; this.formatter = formatter; }
public SendToEmailTraceListenerBuilder(ILoggingConfigurationSendTo context, string listenerName) : base(context) { emailTraceListener = new EmailTraceListenerData { Name = listenerName }; base.AddTraceListenerToSettingsAndCategory(emailTraceListener); }
public void CanUseSSLWhenUnauthenticated() { var listenerData = new EmailTraceListenerData("listener", "[email protected]", "*****@*****.**", "EntLib-Logging:", "has occurred", "smtphost", 25, "formatter", TraceOptions.None, SourceLevels.All, EmailAuthenticationMode.None, null, null, true); Assert.IsTrue(listenerData.UseSSL); }
public void ListenerDataIsCreatedCorrectly() { EmailTraceListenerData listenerData = new EmailTraceListenerData("listener", "[email protected]", "*****@*****.**", "EntLib-Logging:", "has occurred", "smtphost", 25, "formatter"); Assert.AreSame(typeof(EmailTraceListener), listenerData.Type); Assert.AreSame(typeof(EmailTraceListenerData), listenerData.ListenerDataType); Assert.AreEqual("listener", listenerData.Name); Assert.AreEqual("smtphost", listenerData.SmtpServer); Assert.AreEqual("formatter", listenerData.Formatter); }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with the raw data to create and email, the logentry, and the formatter /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="logEntry">The LogEntry <see cref="LogEntry"/> to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> /// <param name="authenticationMode">Authenticate mode to use when connecting to SMTP server.</param> /// <param name="userName">User name to send to SMTP server if using username/password authentication.</param> /// <param name="password">Password to send to SMTP server if using username/password authentication.</param> /// <param name="useSSL">Use SSL to connect to STMP server - if true, yes, if false, no.</param> public EmailMessage(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, LogEntry logEntry, ILogFormatter formatter, EmailAuthenticationMode authenticationMode, string userName, string password, bool useSSL) { this.configurationData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty) { AuthenticationMode = authenticationMode, UserName = userName, Password = password, UseSSL = useSSL }; this.logEntry = logEntry; this.formatter = formatter; }
public void CanCreateInstanceFromGivenConfiguration() { EmailTraceListenerData listenerData = new EmailTraceListenerData("listener", "[email protected]", "*****@*****.**", "EntLib-Logging:", "has occurred", "smtphost", 25, "formatter"); MockLogObjectsHelper helper = new MockLogObjectsHelper(); helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "foobar template")); TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache); Assert.IsNotNull(listener); Assert.AreEqual("listener", listener.Name); Assert.AreEqual(listener.GetType(), typeof(EmailTraceListener)); Assert.IsNotNull(((EmailTraceListener)listener).Formatter); Assert.AreEqual(((EmailTraceListener)listener).Formatter.GetType(), typeof(TextFormatter)); Assert.AreEqual("foobar template", ((TextFormatter)((EmailTraceListener)listener).Formatter).Template); }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds an <see cref="EmailTraceListener"/> based on an instance of <see cref="EmailTraceListenerData"/>. /// </summary> /// <seealso cref="TraceListenerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="EmailTraceListenerData"/>.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="EmailTraceListener"/>.</returns> public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { EmailTraceListenerData castedObjectConfiguration = (EmailTraceListenerData)objectConfiguration; ILogFormatter formatter = GetFormatter(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new EmailTraceListener( castedObjectConfiguration.ToAddress, castedObjectConfiguration.FromAddress, castedObjectConfiguration.SubjectLineStarter, castedObjectConfiguration.SubjectLineEnder, castedObjectConfiguration.SmtpServer, castedObjectConfiguration.SmtpPort, formatter); return(createdObject); }
public void CanDeserializeSerializedConfiguration() { string name = "name"; string toAddress = "[email protected]"; string fromAddress = "*****@*****.**"; string subjectStarter = "EntLib-Logging:"; string subjectEnder = "has occurred"; string server = "smtphost"; int port = 25; string formatter = "formatter"; TraceListenerData data = new EmailTraceListenerData(name, toAddress, fromAddress, subjectStarter, subjectEnder, server, port, formatter, TraceOptions.Callstack); LoggingSettings settings = new LoggingSettings(); settings.TraceListeners.Add(data); IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(); sections[LoggingSettings.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName); Assert.AreEqual(1, roSettigs.TraceListeners.Count); Assert.IsNotNull(roSettigs.TraceListeners.Get(name)); Assert.AreEqual(TraceOptions.Callstack, roSettigs.TraceListeners.Get(name).TraceOutputOptions); Assert.AreSame(typeof(EmailTraceListenerData), roSettigs.TraceListeners.Get(name).GetType()); Assert.AreSame(typeof(EmailTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType); Assert.AreSame(typeof(EmailTraceListener), roSettigs.TraceListeners.Get(name).Type); Assert.AreEqual(formatter, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter); Assert.AreEqual(fromAddress, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).FromAddress); Assert.AreEqual(port, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).SmtpPort); Assert.AreEqual(server, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).SmtpServer); Assert.AreEqual(subjectEnder, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).SubjectLineEnder); Assert.AreEqual(subjectStarter, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).SubjectLineStarter); Assert.AreEqual(toAddress, ((EmailTraceListenerData)roSettigs.TraceListeners.Get(name)).ToAddress); }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with email configuration data, logentry, and formatter /// </summary> /// <param name="configurationData">The configuration data <see cref="EmailTraceListenerData"/> /// that represents how to create the email message</param> /// <param name="logEntry">The LogEntry <see cref="LogEntry"/> to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> public EmailMessage(EmailTraceListenerData configurationData, LogEntry logEntry, ILogFormatter formatter) { this.configurationData = configurationData; this.logEntry = logEntry; this.formatter = formatter; }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with the raw data to create and email, a message, and the formatter /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="message">Represents the message to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> public EmailMessage(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, string message, ILogFormatter formatter) { this.configurationData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty); this.logEntry = new LogEntry(); logEntry.Message = message; this.formatter = formatter; }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with email configuration data, logentry, and formatter /// </summary> /// <param name="configurationData">The configuration data <see cref="EmailTraceListenerData"/> /// that represents how to create the email message</param> /// <param name="logEntry">The LogEntry <see cref="LogEntry"/> to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> public EmailMessage(EmailTraceListenerData configurationData, LogEntry logEntry, ILogFormatter formatter) { this.configurationData = configurationData; this.logEntry = logEntry; this.formatter = formatter; }
public MockEmailTraceListener(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, ILogFormatter formatter) : base(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, formatter) { emailData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty); }
public MockEmailMessage(EmailTraceListenerData emailParameters, LogEntry logEntry, ILogFormatter formatter) : base(emailParameters, logEntry,formatter) { }
public void CanCreatePoliciesForEmailTraceListener() { EmailTraceListenerData listenerData = new EmailTraceListenerData("listener", "to address", "from address", "starter", "ender", "smtp", 25, ""); listenerData.TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId; listenerData.Filter = SourceLevels.Error; loggingSettings.TraceListeners.Add(listenerData); using (var container = CreateContainer()) { EmailTraceListener createdObject = (EmailTraceListener)container.Resolve<TraceListener>("listener\u200cimplementation"); Assert.IsNotNull(createdObject); Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions); Assert.IsNotNull(createdObject.Filter); Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter)); Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType); Assert.IsNull(createdObject.Formatter); } }
public void CanSetUserNameAndPassword() { var listenerData = new EmailTraceListenerData("listener", "[email protected]", "*****@*****.**", "EntLib-Logging:", "has occurred", "smtphost", 25, "formatter", TraceOptions.None, SourceLevels.All, EmailAuthenticationMode.UserNameAndPassword, "user", "secret", true); Assert.AreEqual(EmailAuthenticationMode.UserNameAndPassword, listenerData.AuthenticationMode); Assert.AreEqual("user", listenerData.UserName); Assert.AreEqual("secret", listenerData.Password); }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with the raw data to create and email, the logentry, and the formatter /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="logEntry">The LogEntry <see cref="LogEntry"/> to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> /// <param name="authenticationMode">Authenticate mode to use when connecting to SMTP server.</param> /// <param name="userName">User name to send to SMTP server if using username/password authentication.</param> /// <param name="password">Password to send to SMTP server if using username/password authentication.</param> /// <param name="useSSL">Use SSL to connect to STMP server - if true, yes, if false, no.</param> public EmailMessage(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, LogEntry logEntry, ILogFormatter formatter, EmailAuthenticationMode authenticationMode, string userName, string password, bool useSSL) { this.configurationData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty) { AuthenticationMode = authenticationMode, UserName = userName, Password = password, UseSSL = useSSL }; this.logEntry = logEntry; this.formatter = formatter; }
public void CanDeserializeSerializedConfiguration() { const string name = "name"; const string toAddress = "[email protected]"; const string fromAddress = "*****@*****.**"; const string subjectStarter = "EntLib-Logging:"; const string subjectEnder = "has occurred"; const string server = "smtphost"; const int port = 25; const string formatter = "formatter"; const string user = "******"; const string password = "******"; var data = new EmailTraceListenerData { Name = name, ToAddress = toAddress, FromAddress = fromAddress, SubjectLineStarter = subjectStarter, SubjectLineEnder = subjectEnder, SmtpServer = server, SmtpPort = port, Formatter = formatter, TraceOutputOptions = TraceOptions.Callstack, Filter = SourceLevels.Critical, AuthenticationMode = EmailAuthenticationMode.UserNameAndPassword, UserName = user, Password = password, UseSSL = true }; LoggingSettings settings = new LoggingSettings(); settings.TraceListeners.Add(data); IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(); sections[LoggingSettings.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); LoggingSettings roSettings = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName); Assert.AreEqual(1, roSettings.TraceListeners.Count); var loadedData = (EmailTraceListenerData) roSettings.TraceListeners.Get(name); Assert.IsNotNull(loadedData); Assert.AreEqual(TraceOptions.Callstack, loadedData.TraceOutputOptions); Assert.AreEqual(SourceLevels.Critical, loadedData.Filter); Assert.AreSame(typeof(EmailTraceListenerData), loadedData.GetType()); Assert.AreSame(typeof(EmailTraceListenerData), loadedData.ListenerDataType); Assert.AreSame(typeof(EmailTraceListener), loadedData.Type); Assert.AreEqual(formatter, loadedData.Formatter); Assert.AreEqual(fromAddress, loadedData.FromAddress); Assert.AreEqual(port, loadedData.SmtpPort); Assert.AreEqual(server, loadedData.SmtpServer); Assert.AreEqual(subjectEnder, loadedData.SubjectLineEnder); Assert.AreEqual(subjectStarter, loadedData.SubjectLineStarter); Assert.AreEqual(toAddress, loadedData.ToAddress); Assert.AreEqual(EmailAuthenticationMode.UserNameAndPassword, loadedData.AuthenticationMode); Assert.AreEqual(user, loadedData.UserName); Assert.AreEqual(password, loadedData.Password); Assert.IsTrue(loadedData.UseSSL); }