From 9e438e7790a7275550180369876a39ffdeb72384 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Sat, 26 Aug 2023 15:52:23 +0200 Subject: [PATCH] Reduce InternalLogger.Debug logging to one line --- src/NLog.MailKit/MailTarget.cs | 12 ++++++------ .../IntegrationTests/MailTargetIntegrationTests.cs | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/NLog.MailKit/MailTarget.cs b/src/NLog.MailKit/MailTarget.cs index c1f2131..e10cf11 100644 --- a/src/NLog.MailKit/MailTarget.cs +++ b/src/NLog.MailKit/MailTarget.cs @@ -318,7 +318,7 @@ private void ProcessSingleMailMessage(IEnumerable 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); @@ -330,7 +330,7 @@ private void ProcessSingleMailMessage(IEnumerable 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. @@ -338,20 +338,20 @@ private void ProcessSingleMailMessage(IEnumerable events) // 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) { diff --git a/test/NLog.MailKit.Tests/IntegrationTests/MailTargetIntegrationTests.cs b/test/NLog.MailKit.Tests/IntegrationTests/MailTargetIntegrationTests.cs index a15f7ba..2c6f8fd 100644 --- a/test/NLog.MailKit.Tests/IntegrationTests/MailTargetIntegrationTests.cs +++ b/test/NLog.MailKit.Tests/IntegrationTests/MailTargetIntegrationTests.cs @@ -47,6 +47,15 @@ public void SendMailWithCC() AssertMailBox("do_not_reply@domain.com", transactions[0].To[1]); } + [Fact] + public void SendMailWithPriority() + { + SendTest(() => + { + CreateNLogConfig(priority: MimeKit.MessagePriority.Urgent.ToString()); + }, 1); + } + [Fact] public void SendMailWithHeader() { @@ -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") { @@ -130,7 +139,8 @@ private static MailTarget CreateNLogConfig(string username = null, string passwo To = "mock@mock.com", From = "hi@unittest.com", SmtpUserName = username, - SmtpPassword = password + SmtpPassword = password, + Priority = priority, }; if (headerName != null)