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

MailTarget is supported by NetStandard2.0 (but without SmtpSection) #2401

Merged
merged 1 commit into from
Nov 18, 2017
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
2 changes: 1 addition & 1 deletion src/NLog/Internal/ISmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//

#if !SILVERLIGHT && !NETSTANDARD
#if !SILVERLIGHT && !NETSTANDARD1_5

namespace NLog.Internal
{
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Internal/MySmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//

#if !SILVERLIGHT && !NETSTANDARD
#if !SILVERLIGHT && !NETSTANDARD1_5

namespace NLog.Internal
{
Expand Down
18 changes: 10 additions & 8 deletions src/NLog/Targets/MailTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

using JetBrains.Annotations;

#if !SILVERLIGHT && !NETSTANDARD
#if !SILVERLIGHT && !NETSTANDARD1_5

namespace NLog.Targets
{
Expand All @@ -44,14 +44,16 @@ namespace NLog.Targets
using System.Net.Mail;
using System.Text;
using System.IO;
using Common;
using Config;
using Internal;
using Layouts;
using NLog.Common;
using NLog.Config;
using NLog.Internal;
using NLog.Layouts;

// For issue #1351 - These are not available for Android or IOS
#if !__ANDROID__ && !__IOS__
#if !__ANDROID__ && !__IOS__
using System.Configuration;
#endif
#if !__ANDROID__ && !__IOS__&& !NETSTANDARD
using System.Net.Configuration;
#endif

Expand Down Expand Up @@ -111,7 +113,7 @@ public MailTarget()
Timeout = 10000;
}

#if !__ANDROID__ && !__IOS__
#if !__ANDROID__ && !__IOS__ && !NETSTANDARD
private SmtpSection _currentailSettings;

/// <summary>
Expand Down Expand Up @@ -167,7 +169,7 @@ public Layout From
{
get
{
#if !__ANDROID__ && !__IOS__
#if !__ANDROID__ && !__IOS__ && !NETSTANDARD
if (UseSystemNetMailSettings)
{
// In contrary to other settings, System.Net.Mail.SmtpClient doesn't read the 'From' attribute from the system.net/mailSettings/smtp section in the config file.
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Targets/SmtpAuthenticationMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//

#if !SILVERLIGHT && !NETSTANDARD
#if !SILVERLIGHT && !NETSTANDARD1_5

namespace NLog.Targets
{
Expand Down
12 changes: 9 additions & 3 deletions tests/NLog.UnitTests/Targets/MailTargetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//

#if !NETSTANDARD
#if !NETSTANDARD1_5

namespace NLog.UnitTests.Targets
{
Expand All @@ -44,7 +44,9 @@ namespace NLog.UnitTests.Targets
using NLog.Targets;
using Xunit;
using System.IO;
#if !NETSTANDARD
using System.Net.Configuration;
#endif

public class MailTargetTests : NLogTestBase
{
Expand Down Expand Up @@ -757,7 +759,9 @@ public void MailTarget_UseSystemNetMailSettings_True_ReadFromFromConfigFile_dont
SmtpPort = 27,
Body = "${level} ${logger} ${message}",
UseSystemNetMailSettings = true,
#if !NETSTANDARD
SmtpSection = new SmtpSection { From = "config@foo.com" }
#endif
};
Assert.Equal("'nlog@foo.com'", mmt.From.ToString());

Expand All @@ -769,7 +773,7 @@ public void MailTarget_UseSystemNetMailSettings_True_ReadFromFromConfigFile_dont
[Fact]
public void MailTarget_UseSystemNetMailSettings_True_ReadFromFromConfigFile()
{

#if !NETSTANDARD
var mmt = new MailTarget()
{
From = null,
Expand All @@ -785,12 +789,13 @@ public void MailTarget_UseSystemNetMailSettings_True_ReadFromFromConfigFile()
mmt.Initialize(null);

Assert.Equal("'config@foo.com'", mmt.From.ToString());
#endif
}

[Fact]
public void MailTarget_UseSystemNetMailSettings_False_ReadFromFromConfigFile()
{

#if !NETSTANDARD
var mmt = new MailTarget()
{
From = null,
Expand All @@ -804,6 +809,7 @@ public void MailTarget_UseSystemNetMailSettings_False_ReadFromFromConfigFile()
Assert.Null(mmt.From);

Assert.Throws <NLogConfigurationException>(() => mmt.Initialize(null));
#endif
}

[Fact]
Expand Down