Is there an smtp application in Log4Net that supports TLS encryption?

As indicated in the header, I am having trouble finding an appender that claims to support the TLS encryption standard.

I'm trying to use SmtpAppender, but I can’t get it working and suspect that it is connected to an SMTP server that requires TLS encryption, and SmtpAppender may not support this.

setup from the Office365 manual

Guide

Used configuration:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="my email" /> <from value="The senders email" /> <Username value="JohnDoe"></Username> <password value="NoWay" ></password> <authentication value="Basic"></authentication> <subject value="Test message" /> <smtpHost value="pod51011.outlook.com" /> <port value="587" /> <bufferSize value="512" /> <lossy value="true" /> <EnableSsl value="true"/> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="INFO"/> </evaluator> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" /> </layout> </appender> 
+7
source share
2 answers

After some further research and actual testing using the latest version of Log4Net 1.2.11, the answer is: Yes.

The question answered this question a bit. C # ASP.NET Send email via TLS and study the Log4Net snooping problem to allow smtp for ssl authentication and with certificates. It is documented that Log4Net has an EnableSsl switch, which, as the name implies, enables SSL support, which, under the first link, falls under TLS.

+5
source

Another option for those who are not ready to upgrade to 1.2.11 is to add a custom application:

 /// <summary> /// This is a custom appender so that we can enable SSL properly (and support TLS) /// </summary> public class SmtpCustomAppender : SmtpAppender { public bool EnableSsl { get; set; } public SmtpCustomAppender() { Authentication = SmtpAuthentication.None; Port = 25; //0x19; //Port = 587; // 0x24b; Priority = MailPriority.Normal; EnableSsl = false; } /// <summary> /// Send the email message - this overrides the email sender so that we can add enabling SSL /// </summary> /// <param name="messageBody">the body text to include in the mail</param> protected override void SendEmail(string messageBody) { SmtpClient client = new SmtpClient(); if (!string.IsNullOrEmpty(SmtpHost)) { client.Host = SmtpHost; } client.Port = Port; client.EnableSsl = EnableSsl; client.DeliveryMethod = SmtpDeliveryMethod.Network; switch (Authentication) { case SmtpAuthentication.Basic: client.Credentials = new NetworkCredential(Username, Password); break; case SmtpAuthentication.Ntlm: client.Credentials = CredentialCache.DefaultNetworkCredentials; break; } MailMessage message = new MailMessage { Body = messageBody, From = new MailAddress(From) }; message.To.Add(To); message.Subject = Subject; message.Priority = Priority; client.Send(message); } } 

Then, in your configuration file, you just need to install what was previously used in SmtpAppender into the full namespace of your user application.

 <appender name="ErrorSmtpAppender" type="SomeProject.Infrastructure.Logging.Log4netAppenders.SmtpCustomAppender"> 

You can then add <enablessl value="true" /> to your log application.

I created a gist to show you what it looks like.

+1
source

All Articles