aspNetEmail

Attachment.CreateFromException Method 

Creates an Attachment from a .NET exception object.

public static Attachment CreateFromException(
   Exception exception
);

Parameters

exception
A .NET Exception object

Remarks

This method is useful in emailing exceptions from your .NET applications. This method will serialize the exception using a BinaryFormatter, so it can be deserialized for later inspection.

Example

[C#]
            try
            {
            	byte[] data = FetchData(); //some method that returns data
            }
            catch( Exception ex )
            {
            	EmailMessage m = new EmailMessage("127.0.0.1" );
            	m.From = "me@mycompany.com";
            	m.To = "you@yourcompany.com";
            	m.Subject = "exception occurred during FetchData()";
            
            	m.FormatException( MailFormat.Html, ex, false, ServerErrorSection.All );
            
            
            	//create an attachment from the exception and also add it
            	Attachment a = Attachment.CreateFromException( ex );
            	m.AddAttachment( a );
            
            	m.Send();
            }
            
[VB.NET]
            Try
               Dim data As Byte() = FetchData() 'some method that returns data
            Catch ex As Exception
               Dim m As New EmailMessage("127.0.0.1")
               m.From = "me@mycompany.com"
               m.To = "you@yourcompany.com"
               m.Subject = "exception occurred during FetchData()"
               
               m.FormatException(MailFormat.Html, ex, False, ServerErrorSection.All)
               
               
               'create an attachment from the exception and also add it
               Dim a As Attachment = Attachment.CreateFromException(ex)
               m.AddAttachment(a)
               
               m.Send()
            End Try
            

See Also

Attachment Class | aspNetEmail Namespace