aspNetEmail

EmailMessage.SendASPNETException Method (String, Exception, ServerErrorSection[])

Formats and sends the base ASP.NET exception. Useful to administrators and developers who monitor their applications.

public static void SendASPNETException(
   string keyPrefix,
   Exception ex,
   params ServerErrorSection[] sections
);

Parameters

keyPrefix
The config key prefix to use.
ex
The exception to format. If the exception is null, the HttpContext.Current.Error.GetBaseError() will be used.
sections
Various server information sections

Remarks

The properties for the EmailMessage object are loaded from the web.config.

Example

[web.config]
            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
            <appSettings>
            <add key="EmailMessage.To" value="webmaster@mycompany.com"></add>
            <add key="EmailMessage.FromAddress" value="webmaster@mycompany.com"></add>
            <add key="EmailMessage.Server" value="127.0.0.1"></add>
            <add key="EmailMessage.Subject" value="error in asp.net app"></add>
            <add key="EmailMessage.BodyFormat" value="html"></add>
            
            <!-- with the key prefix 'error_', the values for EmailMessage.Subject and EmailMessage.To will be over written -->
            <add key="error_EmailMessage.Subject" value="Error On Website"></add>
            <add key="error_EmailMessage.To" value="admin@mycompany.com;webmaster@mycompany.com"></add>
            
            </appSettings>
            
            <system.web>
            
            </system.web>
            </configuration>
            
            
[C#]
            protected void Application_Error(Object sender, EventArgs e)
            {
            
            	//send any exception that occurrs based upon web.config settings
            	EmailMessage.SendASPNETException( "error_", Server.GetLastError(), ServerErrorSection.Exception, ServerErrorSection.ServerVariables  );
            
            }
            
[Visual Basic]
            Protected Sub Application_Error(sender As [Object], e As EventArgs)
            
            	'send any exception that occurrs based upon web.config settings
            	EmailMessage.SendASPNETException( "error_", Server.GetLastError(), ServerErrorSection.Exception, ServerErrorSection.ServerVariables  )
            
            End Sub 'Application_Error		
            

See Also

EmailMessage Class | aspNetEmail Namespace | EmailMessage.SendASPNETException Overload List | LoadFromConfig