Anyone know how to use the MS Exception Blocks? RRS feed

  • Question

  • User802733638 posted
    I am having difficulty setting up the application block samples. Basically I would like to try out the exception to send emails. Could someone explain how I can incorporate this into my application.
    Saturday, April 9, 2005 5:45 AM

All replies

  • User44722370 posted

    To send an emial using the EMAB you would need to first create a Custom Publisher.

    Then setup the web.config file approriately and then use the ExceptionManager to .Publish your errors.

    This is a sample email publisher that I found out on the web, it works well.

    Imports Microsoft.ApplicationBlocks.ExceptionManagement

    Imports System.Collections.Specialized

    Imports System.Web.Mail

    Public Class EMeMail

    Implements IExceptionPublisher

    Public Sub Publish(ByVal exception As Exception, _

    ByVal additionalInfo As NameValueCollection, _

    ByVal configSettings As NameValueCollection) _

    Implements IExceptionPublisher.Publish

    Dim strFromEmail As String

    Dim strToEmail As String

    Dim strSubject As String

    Dim strFormName As String

    Dim strAppName As String

    If Not (additionalInfo Is Nothing) Then

    ' Retrieve Additional Info

    With additionalInfo

    strFormName = .Item("FormName")

    strAppName = .Item("ApplicationName")

    End With

    End If

    If Not (configSettings Is Nothing) Then

    ' Retrieve Attributes from Config File

    With configSettings

    strFromEmail = .Item("FromEMail")

    strToEmail = .Item("ToEMail")

    strSubject = .Item("Subject")

    End With

    End If

    strSubject &= " - " & strFormName & _

    " - " & strAppName


    ' Send Exception via Email

    SmtpMail.SmtpServer = ""

    SmtpMail.Send(strFromEmail, strToEmail, _

    strSubject, exception.ToString())

    Catch exp As Exception

    ' Log error from Exception Manager

    ' into Application Event Log

    Throw exp

    End Try

    End Sub

    End Class

    Then your config file would look some thing like this
    <?xml version="1.0" encoding="utf-8" ?>



    <section name="exceptionManagement" type="Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManagerSectionHandler,Microsoft.ApplicationBlocks.ExceptionManagement" />



    <!-- Default Publisher -->

    <!-- NOTE: logName is name of app,

    applicationName is name of Log -->

    <publisher mode="on" logName="Tires Plus Apps"

    applicationName="Client" assembly="Client"

    type="Client.DefaultPublisher" />


    <!-- Publishes to E-Mail -->

    <publisher mode="on" applicationName="Client" assembly="Client" type="Client.EMeMail" FromEMail="goakes@Tiresplus.com" ToEMail="goakes@tiresplus.com" Subject="Exception from Client website" />



    Thursday, April 28, 2005 1:53 PM