EntLib 5.0.414.0 EmailTraceListener - wouldn't send an email

Topics: Exception Handling Application Block
Sep 30, 2010 at 5:16 PM

Hi all,

I'm successfully using prior versions of EntLib and having no issues sending an emails whenever exception occurs.  However, with EntLib 5.0.414.0 the email just would't send.  I checked a couple of possible situations (like verifying if message ended up in the spam box or SMTP relay permissions for my IP failure) and nothing wrong could be found.  Code like the following is working fine:

 

 
  
        MailMessage m = new MailMessage("zzADT@morganlewis.com", "avassilev@morganlewis.com", "PageLoad", "some text");
        m.IsBodyHtml = true;
        SmtpClient client = new SmtpClient("corelay.morganlewis.net", 25);
        client.Send(m);

 

What possibly can be wrong?  Please advise.  Something else to keep in mind - Windows event log has been populated with the exception just fine, it's the email that's not being sent.

Following is the call on Global.asax

    void Application_Error(object sender, EventArgs e) { 
        Exception exptn = Server.GetLastError();
        ExceptionPolicy.HandleException(exptn, "ExceptionHandlingPolicy");
    }
Also, below is essentials from my web.config:
  
  
  <section name="loggingConfiguration" 
           type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
           requirePermission="false" />
  <section name="exceptionHandling" 
           type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
           requirePermission="false" />
 </configSections>
 <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
  defaultCategory="General">
  <listeners>
   <add name="Email Trace Listener" 
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        toAddress="avassilev@morganlewis.com" 
        fromAddress="zzADT_Error_Reporting@morganlewis.com"
        subjectLineStarter="MLQueue" 
        subjectLineEnder="" 
        smtpServer="corelay.morganlewis.net"
        smtpPort="25" 
        formatter="Text Formatter" 
        traceOutputOptions="None" />
   <add name="Event Log Listener" 
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" 
        formatter="Text Formatter"
        log="" 
        machineName="." 
        traceOutputOptions="None" />
  </listeners>
  <formatters>
   <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
    name="Text Formatter" />
  </formatters>
  <categorySources>
   <add switchValue="All" name="General">
    <listeners>
     <add name="Event Log Listener" />
     <add name="Email Trace Listener" />
    </listeners>
   </add>
  </categorySources>
  <specialSources>
   <allEvents switchValue="All" name="All Events">
    <listeners>
     <add name="Email Trace Listener" />
     <add name="Event Log Listener" />
    </listeners>
   </allEvents>
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
     <add name="Event Log Listener" />
     <add name="Email Trace Listener" />
    </listeners>
   </errors>
  </specialSources>
 </loggingConfiguration>
 <exceptionHandling>
  <exceptionPolicies>
   <add name="ExceptionHandlingPolicy">
    <exceptionTypes>
     <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      postHandlingAction="NotifyRethrow">
      <exceptionHandlers>
       <add name="Logging Exception Handler" 
            type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            logCategory="General" 
            eventId="100" 
            severity="Error" 
            title="Enterprise Library Exception Handling"
            formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="0" />
      </exceptionHandlers>
     </add>
    </exceptionTypes>
   </add>
  </exceptionPolicies>
 </exceptionHandling>
Sep 30, 2010 at 6:11 PM
Edited Sep 30, 2010 at 6:16 PM

Wasn't there any other error log in the event viewer indicating why logging using email trace listener failed? 

Have you verified that this same actual configuration works for version 4.1 (replacing references to 5.0.414.0 to 4.1.0.0)

 

Sarah Urmeneta
Global Technology and Solution
Avanade, Inc.
entlib.support@avanade.com

Sep 30, 2010 at 8:33 PM

I figured it out - <specialSources> section was not configured properly.  Below is the working version.  Thanks for your help.

 

  <specialSources>
   <allEvents switchValue="All" name="All Events" />
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
     <add name="Email Trace Listener" />
     <add name="Event Log Listener" />
    </listeners>
   </errors>
  </specialSources>
Oct 1, 2010 at 5:09 AM

I think logging failed.   What happens is that there was an error which occurred while logging and the log message wasn't logged to its destination.  

My theory is that you're unable to log using Event Log Trace Listener which causes the error d trigerring the logging of that error using the listeners under the Logging Errors and Warnings.  Check if you got the expected message in the Event Log.  If there isn't then my theory is right and you need to find out why logging to event log fails.  It might be a permission issue.

 

Sarah Urmeneta
Global Technology and Solution
Avanade, Inc.
entlib.support@avanade.com