Nlog: Target cannot be found: 'Mail'

Created on 21 Oct 2016  路  11Comments  路  Source: NLog/NLog

Hello. I use ASP.NET CORE. I try to send log to email. I use try to use config from this url https://github.com/nlog/NLog/wiki/Mail-target
and after start app i can see error:

2016-10-21 18:13:45.4149 Error Error in Parsing Configuration File. Exception: NLog.NLogConfigurationException: Exception occurred when loading configuration fromnlog.config ---> System.ArgumentException: Target cannot be found: 'Mail'
   at NLog.Config.Factory`2.CreateInstance(String name)
   at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement targetsElement)
   at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String filePath, Boolean autoReloadDefault)
   at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
   --- End of inner exception stack trace ---

my config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="Warn"
      internalLogFile="c:\temp\internal-nlog.txt">
  <extensions>
    <!--enable NLog.Web for ASP.NET Core-->
    <add assembly="NLog.Web.AspNetCore"/>
  </extensions> 
  <!-- define various log targets -->
  <targets>
      <target xsi:type="Mail"
              name="send_to_email"
              header="${appdomain}"
              footer="${guid}"
              layout="Layout"
              html="true"
              addNewLines="true"
              replaceNewlineWithBrTagInHtml="true"
              encoding="UTF-8"
              subject="Layout"
              to="to"
              from="from"
              body="${message}"
              smtpUserName="[email protected]"
              enableSsl="true"
              smtpPassword="passsword"
              smtpAuthentication="Basic"
              smtpServer="[email protected]"
              smtpPort="465"
              useSystemNetMailSettings="false"
              smtpDeliveryMethod ="Network"
              timeout="60" /> 

    <target xsi:type="File" name="allfile" fileName="c:\temp\nlog-all-${shortdate}.log"
              layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" />




  </targets>

  <rules>
    <!--All logs, including from Microsoft-->
    <logger name="*" minlevel="Error" writeTo="send_to_email" />
    <logger name="*" minlevel="Error" writeTo="allfile" />

    <!--Skip Microsoft logs and so log only own logs-->

  </rules>
</nlog>

Please help me.

.NET core mail-target question

All 11 comments

The mail target isn't supported in net core as Microsoft didn't port the mail classes. See link platform support.

isn't that possible to reference an external library for mail support in .netcore and as soon as microsoft port those classes, replace by the default ?

You could make an add-on for NLog, I could guide you how-to. It should be a separate Nuget package IMO. The add-on could use the library MailKit, which is .NET Core compatible: https://www.nuget.org/packages/MailKit/

Currently this hasn't prio at our site.

System.Mail will be ported with NETCORE 2, then we could restore the current classes for .NET Core

hello ,i also have this problem . did you have solution

The mail target isn't supported in net core as Microsoft didn't port the mail classes. See link platform support.
https://github.com/NLog/NLog/wiki/platform-support

I close this one in favor of https://github.com/NLog/NLog/issues/1614. This is on the list, but we could use some help.

System.Mail will be ported with NETCORE 2, then we could restore the current classes for .NET Core

hello - do you have source for that? thanks @304NotModified

While waiting for System.Mail, then one can checkout: https://www.nuget.org/packages/NLog.mailkit

Is this issue resolved ?

Have you ported the class now?

As we can see it has been updated in .Net Core 2
Reference link:
https://dotnetcoretutorials.com/2017/08/20/sending-email-net-core-2-0/

This has been solved as there is a NLog.Mailkit package! => https://www.nuget.org/packages/NLog.MailKit/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smeegoan picture smeegoan  路  3Comments

MaximRouiller picture MaximRouiller  路  3Comments

imanushin picture imanushin  路  3Comments

BobSeu picture BobSeu  路  3Comments

FaMouZx3 picture FaMouZx3  路  3Comments