Application_Error logging + Mail Target = infinite loop

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Application_Error logging + Mail Target = infinite loop

Yosi H
Hi,
i use this code:

       void Application_Error(object sender, EventArgs e)
       {
            Exception lastException = Server.GetLastError();
            NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
            logger.Fatal(lastException);
        }
in order to handle general errors on my web site
i works good for me on File target
but when i use the Mail target it make an infinite loop

what is the reason for that?

Thanks,
Yosi

This is my nlog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog throwExceptions="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <targets>
   
    <target name="logfile" xsi:type="File" fileName="${basedir}\nLogs\ ${shortdate}.txt" layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}" />
    <target name="gmail" type="Mail"
            smtpServer="smtp.gmail.com"
            smtpPort="587"
            smtpAuthentication="Basic"
            smtpUsername="xxx.xxx@gmail.com"
            smtpPassword="xxxx"
            enableSsl="true"
            from="xxx.xxx@gmail.com"
            to="xxx.xxx@gmail.com"
            subject="xxx log ${longdate} ${machinename}"
            body="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}"
          />
   
  </targets>
  <rules>
    <logger name="*"  minlevel="Debug" writeTo="logfile,gmail" />
  </rules>
</nlog>