Wednesday, March 14, 2007

EHAB Continued....

Whole day was working on EHAB and finally implemented a custom publisher !

Create the Custom Publisher Class

1) In the Exception Application block, i added a VB class called "CustomPublisher"
2) Code for the class file would go like this...


Imports Microsoft.ApplicationBlocks.ExceptionManagement
Imports Microsoft.ApplicationBlocks.Data
Imports System.Web
Imports System.Data.SqlClient
Imports System.Data


Public Class CustomPublisher
Implements IExceptionPublisher

Public Sub Publish(ByVal exception As System.Exception, ByVal additionalInfo As NameValueCollection, ByVal configSettings As NameValueCollection) Implements IExceptionPublisher.Publish

Try
Dim strConn As String
strConn = ConfigurationSettings.AppSettings.Get("ConnStr").ToString()
-- Some how get the Conn string
SqlHelper.ExecuteNonQuery(strConn,CommandType.StoredProcedure,"usp_InsertException")
-- Some Stored proc to insert ur exception...
Catch ex As exception
-- Do something to catch the exception here, outta scope of EHAB
End Try
End Sub
End Class



3) Configure the Web.config file...

the contents shud go like this....











Now, note that the assembly name must be the Name of the Assembly where the project is deployed and type should be the class name which overrides the Publish method.


Now, in the project, where ever therez an exception, all we need to do is call the method

ExceptionManager.Publish(ex)


The rest is taken care by EHAB.

Wasted a couple of hours working on App.config file..

Realized that App.Config file is for Windows Applications and
Web.config file is for Web Application...

More to Come on the same...

0 comments: