2010-07-26 42 views
1

我使用企业库5.0与SharePoint登录异常转换SQLdatabase.I使用Windows 7操作系统和Visual Studio 2010中例外策略与数据库跟踪侦听器在企业图书馆5.0没有记录异常到SQL数据库

(1)如链接中所示,我通过在位置(C:\ Documents and Settings \ Venkatesan \ My Documents \ EntLib50Src \ Blocks \ Logging \ Src \ DatabaseTraceListener \ Scripts \ CreateLoggingDb)中运行脚本在SQLEXPRESS中创建了“日志记录”数据库

(2)我打开企业库(EntLib Config .Net 4)中的web.config文件,并提到连接字符串为“data source =。\”的数据库实例(ExampleDatabase)的连接字符串。 (3)我提到了异常策略(MyPolicy),异常类型(All Exceptions),数据库跟踪监听器等等。(3)SQLEXPRESS;集成安全性= SSPI; AttachDBFilename = | DataDirectory | \ Logging.mdf;用户实例= true

上..因此web.config文件如下: 我已经在web.config文件
仅设置所需的部分.. .. .. .. .. (4)我部署所需的DLL在GAC和Web应用程序的bin以及... 以前,我没有在GAC中部署ent lib DLL,但是我有一个错误提到我必须在GAC中部署它们。

(5)我在解决方案项目中添加了ent lib dlls作为参考。

(6)我的项目代码如下:使用系统

;
使用Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
使用Microsoft.Practices.EnterpriseLibrary.Data。SQL;
using Microsoft.Practices.EnterpriseLibrary.Data.SqlCe;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging;
使用Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Database;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.ObjectBuilder2;
使用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;使用Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

命名空间MyEntLibProj.Layouts.MyEntLibProj
{
公共部分类MyApplicationPage:LayoutsPageBase
{
保护无效的Page_Load(对象发件人,EventArgs的)
{
尝试
{
抛出新ArgumentNullException (“这是一个错误!!!!”);
}
catch(Exception ex)
{
Exception ex1;
bool result = ExceptionPolicy.HandleException(ex,“MyPolicy”,out ex1);
if(result)
throw;
}
}
}
}

当我调试代码,虽然我没有得到任何异常,“结果”值是true,则ArgumentNull异常不获取登录到我database.Please帮助我找到了,我会一直错了...

回答

0

我的web.config文件:

<配置>
< configSections>
<节名称= “loggingConfiguration” 类型=“Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,

Microsoft.Practices.EnterpriseLibrary.Logging,版本= 5.0.414.0,文化=中性,

公钥= 31bf3856ad364e35" requirePermission = “真”/>
<节名称= “exceptionHandling” 类型=“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings,Microsoft.Practices.EnterpriseLibrary.ExceptionHandling,版本= 5.0 0.414。0,文化=中性

公钥= 31bf3856ad364e35" requirePermission = “真”/> <节名称= “dataConfiguration” 类型=“Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.Practices.EnterpriseLibrary 。数据,版本= 5.0.414.0,文化=中性公钥= 31bf3856ad364e35" requirePermission = “真”/> ..
< loggingConfiguration NAME = “” tracingEnabled = “真” defaultCategory = “常规”>
<听众>
< 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”/>
<格式化程序>
< add type =“Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextF {0} {0} {0} {0} {0} {0} {0} {0} 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 {} {newline} {} {{{}} {} {} {} {} {} {} {} 应用领域:{localAppDomain} {换行符} 的ProcessID:{localProcessId} {换行符} 进程名称: {localProcessName} {换行符} 主题名称:{threadName} {换行符} 的Win32 的ThreadId:{win32ThreadId} {换行符} 扩展属性:{字典({键} - {值} {换行符})}”名称= “文本格式化”/> < categorySources>
<添加switchValue = “全部”名称= “通用”>
<听众>
<添加名称= “数据库跟踪监听器”/>


< specialSources>
< allEvents switchValue = “所有” NAME = “所有事件”/ >
< notProcessed switchValue = “全部” 名称= “未处理类别”/>
<错误switchValue = “全部” 名称= “错误记录&警告”/>


< exceptionHandling>
< exceptionPolicies>
<添加名称= “MyPolicy”>
< exceptionTypes>
<添加名称= “所有异常” 类型=“系统。例外,mscorlib程序,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089" postHandlingAction = “NotifyRethrow”> <的ExceptionHandlers>
<添加名称= “日志记录异常处理程序” 类型=“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling。 Logging.LoggingExceptionHandler,Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,版本= 5.0.414.0,文化=中性公钥= 31bf3856ad364e35" logCategory = “常规” 事件ID = “100” 严重= “错误” 称号=“企业库 异常处理“ formatterType =”Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35“ 优先= “0”/> < /的ExceptionHandlers> < dataConfiguration defaultDatabase = “ExampleDatabase”/> < connectionStrings>节点
<添加名称= “ExampleDatabase” 的connectionString =“数据源= \ SQLEXPRESS。综合 安全性= SSPI; AttachDBFilename = | DataDirectory目录| \ Logging.mdf;用户实例=真 “的providerName = ”System.Data.SqlClient的“/> .. < SafeControls> <的SafeControl大会=” S ystem.Web,Version = 1.0.5000.0,Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a“Namespace =”System.Web.UI.WebControls“TypeName =”“Safe =”True“AllowRemoteDesigner =”True“SafeAgainstScript =”False“ /> ..
<的SafeControl大会= “Microsoft.Practices.EnterpriseLibrary.Common,版本= 5.0.414.0, 文化=中性公钥= 31bf3856ad364e35” 命名空间= “Microsoft.Practices.EnterpriseLibrary.Common” 类型名=”
“Safe =”True“/> < SafeControl Assembly =”Microsoft.Practices.Unity,Version = 2.0.414.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35“Namespace =”Microsoft.Practices.Unity“TypeName =”“安全=“真”/> <的SafeControl大会= “Microsoft.Practices.Unity.Configuration,版本= 2.0.414.0, 文化=中性公钥= 31bf3856ad364e35” 命名空间= “Microsoft.Practices.Unity.Configuration” 的TypeName =” “安全=” 真“/> < 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" 命名空间= “Microsoft.Practices.EnterpriseLibrary.Logging” 类型名= “”安全=“ 真”/> <的SafeControl大会=“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, 版本= 5.0.414.0, Culture = neutral,PublicKeyToken = 31bf3856ad364e35“ Namespace =”Microsoft.Practices.EnterpriseLibrary.ExceptionHandling。记录 “的TypeName =” “安全=” 真 “/> <的SafeControl大会= ”Microsoft.Practices.EnterpriseLibrary.Data,版本= 5.0.414.0, 文化=中性公钥= 31bf3856ad364e35“ 命名空间=” Microsoft.Practices .EnterpriseLibrary.Data “的TypeName =” “安全=” 真” /> <的SafeControl大会= “Microsoft.Practices.EnterpriseLibrary.Logging.Database, 版本= 5.0.414.0,文化=中性公钥= 31bf3856ad364e35” 命名空间=“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文化=中性, 公钥= 31bf3856ad364e35 “命名空间=” Microsoft.Practices.ServiceLocation “类型名=” “安全=” 真” /> .. ..