Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce InternalLogger.Debug logging to one line #173

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/NLog.MailKit/MailTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private void ProcessSingleMailMessage(IEnumerable<AsyncLogEventInfo> events)
var enableSsl = RenderLogEvent(EnableSsl, lastEvent);
var secureSocketOptions = enableSsl ? SecureSocketOptions.SslOnConnect : RenderLogEvent(SecureSocketOption, lastEvent, DefaultSecureSocketOption);
var smtpPort = RenderLogEvent(SmtpPort, lastEvent);
InternalLogger.Debug("Sending mail to {0} using {1}:{2} (socket option={3})", message.To, renderedHost, smtpPort, secureSocketOptions);
InternalLogger.Debug("Sending mail to {0} using {1}:{2}", message.To, renderedHost, smtpPort);
InternalLogger.Trace(" Subject: '{0}'", message.Subject);
InternalLogger.Trace(" From: '{0}'", message.From);

Expand All @@ -330,28 +330,28 @@ private void ProcessSingleMailMessage(IEnumerable<AsyncLogEventInfo> events)


client.Connect(renderedHost, smtpPort, secureSocketOptions);
InternalLogger.Trace(" Connecting succesfull");
InternalLogger.Trace("{0}: Connecting succesfull", this);

// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");

// Note: only needed if the SMTP server requires authentication

var smtpAuthentication = RenderLogEvent(SmtpAuthentication, LogEventInfo.CreateNullEvent());
var smtpAuthentication = RenderLogEvent(SmtpAuthentication, lastEvent);
if (smtpAuthentication == SmtpAuthenticationMode.Basic)
{
var userName = RenderLogEvent(SmtpUserName, lastEvent);
var password = RenderLogEvent(SmtpPassword, lastEvent);

InternalLogger.Debug("Authenticate with username '{0}'", userName);
InternalLogger.Trace("{0}: Authenticate with username '{1}'", this, userName);
client.Authenticate(userName, password);
}

client.Send(message);
InternalLogger.Debug("Sending mail done. Disconnecting");
InternalLogger.Trace("{0}: Sending mail done. Disconnecting", this);
client.Disconnect(true);
InternalLogger.Debug("Disconnected");
InternalLogger.Trace("{0}: Disconnected", this);

foreach (var ev in events)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public void SendMailWithCC()
AssertMailBox("[email protected]", transactions[0].To[1]);
}

[Fact]
public void SendMailWithPriority()
{
SendTest(() =>
{
CreateNLogConfig(priority: MimeKit.MessagePriority.Urgent.ToString());
}, 1);
}

[Fact]
public void SendMailWithHeader()
{
Expand Down Expand Up @@ -121,7 +130,7 @@ private static SmtpServer.SmtpServer CreateSmtpServer(MessageStore store)
return smtpServer;
}

private static MailTarget CreateNLogConfig(string username = null, string password = null, string headerName = null)
private static MailTarget CreateNLogConfig(string username = null, string password = null, string priority = null, string headerName = null)
{
var target = new MailTarget("mail1")
{
Expand All @@ -130,7 +139,8 @@ private static MailTarget CreateNLogConfig(string username = null, string passwo
To = "[email protected]",
From = "[email protected]",
SmtpUserName = username,
SmtpPassword = password
SmtpPassword = password,
Priority = priority,
};

if (headerName != null)
Expand Down