Reputation: 28
I'm using NLog, and I'm pretty new at logging. I created the log files but somehow I have a problem whit sending e-mails. I followed all instructions but couldn't make it.
Mail settings in configuration tags in web.config:
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory" from="[email protected]">
<network host="localhost"/>
<specifiedPickupDirectory pickupDirectoryLocation="d:\tmp\email"/>
</smtp>
</mailSettings>
</system.net>
And this is the target inside the nlog.config:
<target name="Mail" xsi:type="Mail" html="true" subject="Error Received"
body="${message}"
to="[email protected]"
from="[email protected]"
encoding="UTF-8"
smtpUserName="[email protected]"
enableSsl="false"
smtpPassword="password"
smtpAuthentication="Basic"
smtpServer="smtp.some.com"
smtpPort="25" />
The rule I used:
<logger name="*" minlevel="Error" writeTo="Mail" />
And I called the logger like this:
Logger logger = LogManager.GetCurrentClassLogger();
try{ //something }
catch(Exception ex){ logger.Error(ex); }
And also I'm pretty confused about the places of the settings and configurations. Thank you.
Upvotes: 0
Views: 4964
Reputation: 1070
The body is a layout format, not sure if it will process the ${message} tag. Change ${message] to a layout name that is in nlog.config or leave it off for the ${message}${newline} default.
You can turn on the Internal Debugging
Change the top XML parent to
<nlog internalLogFile="c:\log.txt" internalLogLevel="Trace">
This might give you an idea on the issue. Could be an authentication issue with the server or another issue.
Since you are specifying all the server information in the target, you don't need the web.config settings.
Not sure if it is fixed yet, but you should add a timeout="10000" to the target so it closes the connection.
There is a pretty good example in the NLog Wiki for GMail that works
Upvotes: 3