Quantcast
Channel: BugNET Issue Tracker (Moved to GitHub)
Viewing all articles
Browse latest Browse all 2179

Commented Unassigned: Support for SSL and authentication in LoggingManager mail server settings [115]

$
0
0
The ConfigureEmailLoggingAppender function in LogiingManager.cs should use the same SMTP mail server settings as in the rest of the BugNet application.

You will need to upgrade to the latest log4net.dll version (1.2.11) to get SSL SMTP server support. Also take care of the strong name key throughout the solution when selecting the version with the new key:
[Download Apache log4net](http://logging.apache.org/log4net/download_log4net.cgi)

The ConfigureEmailLoggingAppender function could be updated as follows:

```
public static void ConfigureEmailLoggingAppender()
{
var hier =
(log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();

if (hier == null) return;

var appender = (SmtpAppender)hier.Root.GetAppender("SmtpAppender") ?? new SmtpAppender();

appender.Name = "SmtpAppender";
appender.From = HostSettingManager.Get(HostSettingNames.HostEmailAddress, string.Empty);
appender.To = HostSettingManager.Get(HostSettingNames.ErrorLoggingEmailAddress, string.Empty);
appender.Subject = "BugNET Error";
appender.SmtpHost = HostSettingManager.SmtpServer;
appender.Port = int.Parse(HostSettingManager.Get(HostSettingNames.SMTPPort));
appender.Authentication = SmtpAppender.SmtpAuthentication.None;
appender.Username = string.Empty;
appender.Password = string.Empty;
appender.EnableSsl = Boolean.Parse(HostSettingManager.Get(HostSettingNames.SMTPUseSSL));

if (Convert.ToBoolean(HostSettingManager.Get(HostSettingNames.SMTPAuthentication)))
{
appender.Authentication = SmtpAppender.SmtpAuthentication.Basic;
appender.Username = String.Format("{0}\\{1}", HostSettingManager.Get(HostSettingNames.SMTPDomain, string.Empty), HostSettingManager.Get(HostSettingNames.SMTPUsername, string.Empty) );
appender.Password = HostSettingManager.Get(HostSettingNames.SMTPPassword, string.Empty);
}

//HostSettingManager.Get(HostSettingNames.SMTPAuthentication);
appender.Priority = System.Net.Mail.MailPriority.High;
appender.Threshold = log4net.Core.Level.Error;
appender.BufferSize = 0;

//create patternlayout
var patternLayout = new
log4net.Layout.PatternLayout("%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline");

patternLayout.ActivateOptions();
appender.Layout = patternLayout;
appender.ActivateOptions();

//add appender to root logger
hier.Root.AddAppender(appender);
}
```
Comments: So yes I had to recompile all the source code to be able to use the latest log4net 1.2.11 version with the new strong name (PublicKeyToken=669e0ddf0bb1aa2).

Viewing all articles
Browse latest Browse all 2179

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>