开发者

Exception Policy with DataBase Trace Listener in Enterprise Library 5.0 not logging exception into SQL database

I am using Enterprise library 5.0 with sharepoint to log exception into SQLdatabase.I use Windows 7 OS and Visual Studio 2010.

开发者_StackOverflow中文版(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...


My web.config file:

< configuration>
< configSections>
< section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,

Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral,

PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
< section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,

PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> < section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> ..
< loggingConfiguration name="" tracingEnabled="true" defaultCategory="General" >
< listeners>
< add name="Database Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" databaseInstanceName="ExampleDatabase" writeLogStoredProcName="WriteLog" addCategoryStoredProcName="AddCategory" formatter="Text Formatter" />
< formatters>
< add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp}{newline} Message: {message}{newline} Category: {category}{newline} Priority: {priority}{newline} EventId: {eventid}{newline} Severity:{severity}{newline} Title:{title}{newline} Machine: {localMachine}{newline} App Domain: {localAppDomain}{newline} ProcessId: {localProcessId}{newline} Process Name: {localProcessName}{newline} Thread Name: {threadName}{newline} Win32 ThreadId:{win32ThreadId}{newline} Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter" /> < categorySources>
< add switchValue="All" name="General">
< listeners>
< add name="Database Trace Listener" />


< specialSources>
< allEvents switchValue="All" name="All Events" />
< notProcessed switchValue="All" name="Unprocessed Category" />
< errors switchValue="All" name="Logging Errors & Warnings" />


< exceptionHandling>
< exceptionPolicies>
< add name="MyPolicy">
< exceptionTypes>
< add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow"> < exceptionHandlers>
< add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" priority="0" /> < /exceptionHandlers> < dataConfiguration defaultDatabase="ExampleDatabase" /> < connectionStrings>
< add name="ExampleDatabase" connectionString="datasource=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Logging.mdf;User Instance=true" providerName="System.Data.SqlClient" /> .. < SafeControls> < SafeControl Assembly="System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"Namespace="System.Web.UI.WebControls"TypeName="" Safe="True" AllowRemoteDesigner="True" SafeAgainstScript="False" /> ..
< SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.Common" TypeName="
" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.Unity" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.Unity.Configuration, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.Unity.Configuration" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.Unity.Interception.Configuration, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.Unity.Interception.Configuration" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.Logging" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.Data" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.Logging.Database" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Data.SqlCe, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Practices.EnterpriseLibrary.Data.SqlCe" TypeName="" Safe="True" /> < SafeControl Assembly="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="Microsoft.Practices.ServiceLocation" TypeName="" Safe="True" /> .. ..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜