Reputation: 31
I want my service to send me the error log file to my email I tried this but it didn't work:
<target name="logfile" xsi:type="File" fileName="${basedir}/logs/log.log"
archiveFileName="${basedir}/logs/log.{#####}.txt"
archiveAboveSize="10485760"
archiveNumbering="Sequence"
concurrentWrites="true"
keepFileOpen="false"
layout="${longdate} - ${level:uppercase=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
/>
<target name="logmail"
xsi:type="Mail"
smtpServer="172.XX.XX.XX"
smtpPort="25"
smtpAuthentication="Basic"
smtpUserName="abc@xyz"
smtpPassword="XXXX"
enableSsl="false"
subject="Jobpool Errors"
from="abc@xyz"
to="abc@xyz"
layout ="${longdate} ${uppercase:${level}} ${callsite:className=true:includeSourcePath=true:methodName=true} ${message}${newline}"
useSystemNetMailSettings="false"
timeout="30" />
this is the logger details:
<logger name="*" minlevel="Debug" writeTo="logfile" />
<logger name="*" minlevel="Error" writeTo="logmail" />
<logger name="*" minlevel="Info" writeTo="logmail" />
Upvotes: 0
Views: 2346
Reputation: 11342
The first obvious thing I note is that you've set authentication to None
however you're passing in a username and password. If your SMTP server requires authentication then you will need to change it to Basic
:
smtpAuthentication="Basic"
The next thing to check is whether you have associated this target with any loggers, e.g:
<logger name="*" minLevel="Info" writeTo="logmail" />
Assuming that this is configured correctly the next step is to enable some of the NLog debugging features to try and identify where the failure is happening. First of all you can tell NLog to throw exceptions when an error occurs via the following configuration directive:
<nlog throwExceptions="true" />
If this still doesn't produce anything useful you can also configure NLog to write its internal logging to a file via:
<nlog internalLogFile="file.txt" />
See this section of the NLog configuration wiki page for more info.
Upvotes: 3