I am using Enterprise library 5.0 with sharepoint to log exception into SQLdatabase.I use Windows 7 OS and Visual Studio 2010.
(1) As given in a link, I created 'Logging' database in SQLEXPRESS by running the script in the location (C:\Documents and Settings\Venkatesan\My Documents\EntLib50Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts\CreateLoggingDb)
(2) I Opened the web.config file in enterprise library (EntLib Config .Net 4) and mentioned the connection string for a database instance (ExampleDatabase) with connection string "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Logging.mdf;User Instance=true"
(3) I mentioned the exception policy(MyPolicy) ,exception type(All Exceptions) ,Database trace listener and so on.. and hence the web.config file is as follows:
i ve provided only the required portions in web.config file
..
..
..
..
..
(4) I deployed the required dlls in GAC and in web application's bin as well...
Previously, i had not deployed ent lib dlls in GAC,but i got an error mentioning i must deploy them in GAC.
(5) I Added the ent lib dlls as references in the solution project.
(6) My project code is as follows:
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data.SqlCe;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Database;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.Practices.Unity.InterceptionExtension;
using Microsoft.Practices.Unity.InterceptionExtension.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration; using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
namespace MyEntLibProj.Layouts.MyEntLibProj
{
public partial class MyApplicationPage : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
throw new ArgumentNullException("This is an error!!!!");
}
catch (Exception ex)
{
Exception ex1;
bool result = ExceptionPolicy.HandleException(ex, "MyPolicy", out ex1);
if (result)
throw;
}
}
}
}
When i debug the code, although I am not getting any exception and 'result' value is true, the ArgumentNull Exception is not getting logged into my database.Please help me in finding out where I would have been wrong...