NetTiers 生成完毕后,默认会在Service层使用logging
但是在默认情况下,被捕获的异常没有被抛出,
下面是通过修改entlib.config, 实现 rethrow.
NetTiers 生成完毕后,Service层会使用logging记录异常日志
但是在默认情况下, 被捕获的异常没有被抛出, 下面是通过修改
entlib.config 实现, rethrow Exception.
<configuration>
<exceptionHandling>
<exceptionPolicies>
<add name="NoneExceptionPolicy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add logCategory="Exceptions" eventId="100" severity="Error"
title="TiannuoSA Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.XmlExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
关键部分 postHandlingAction="NotifyRethrow"
完整的xml如下
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
完整的XML
1
<configuration>
2
<configSections>
3
<section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
4
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
5
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
6
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
7
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
8
<section name="netTiersService" type="Moda.Application.Data.Bases.NetTiersServiceSection, Moda.Application.Data" allowDefinition="MachineToApplication" restartOnExternalChanges="true" />
9
</configSections>
10
<securityConfiguration defaultAuthorizationInstance="NetTiers.RuleProvider"
11
defaultSecurityCacheInstance="">
12
<authorizationProviders>
13
<add type="Microsoft.Practices.EnterpriseLibrary.Security.AuthorizationRuleProvider, Microsoft.Practices.EnterpriseLibrary.Security, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
14
name="NetTiers.RuleProvider" />
15
</authorizationProviders>
16
<securityCacheProviders>
17
<add cacheManagerInstanceName="TiannuoSA.Entities.EntityCache"
18
defaultSlidingSessionExpirationInMinutes="10" defaultAbsoluteSessionExpirationInMinutes="60"
19
type="Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.CachingStoreProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
20
name="Caching Store Provider" />
21
</securityCacheProviders>
22
</securityConfiguration>
23
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
24
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
25
<listeners>
26
<add fileName="TiannuoSA.log.exclude" header="----------------------------------------"
27
footer="----------------------------------------" formatter=""
28
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
29
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
30
name="FlatFile TraceListener" />
31![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32
<add databaseInstanceName="TiannuoSA.Data.ConnectionString" writeLogStoredProcName="usp_writelogtodatabase"
33
addCategoryStoredProcName="usp_addcategory" formatter="Text Formatter"
34
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
35
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
36
name="Database Trace Listener" />
37![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
38
</listeners>
39
<formatters>
40
<add template="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId: {eventid} Severity: {severity} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id: {processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties: {dictionary({key} - {value} )}"
41
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
42
name="Text Formatter" />
43
</formatters>
44
<categorySources>
45
<add switchValue="Error" name="Exceptions">
46
<listeners>
47
<add name="Database Trace Listener" />
48
<add name="FlatFile TraceListener" />
49
</listeners>
50
</add>
51
<add switchValue="All" name="General">
52
<listeners>
53
<add name="Database Trace Listener" />
54
<add name="FlatFile TraceListener" />
55
</listeners>
56
</add>
57
</categorySources>
58
<specialSources>
59
<allEvents switchValue="All" name="All Events" />
60
<notProcessed switchValue="All" name="Unprocessed Category" />
61
<errors switchValue="All" name="Logging Errors & Warnings">
62
<listeners>
63
<add name="FlatFile TraceListener" />
64
<add name="Database Trace Listener" />
65
</listeners>
66
</errors>
67
</specialSources>
68
</loggingConfiguration>
69
<exceptionHandling>
70
<exceptionPolicies>
71
<add name="NoneExceptionPolicy">
72
<exceptionTypes>
73
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
74
postHandlingAction="NotifyRethrow" name="Exception">
75
<exceptionHandlers>
76
<add logCategory="Exceptions" eventId="100" severity="Error"
77
title="TiannuoSA Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.XmlExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
78
priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
79
name="Logging Handler" />
80
</exceptionHandlers>
81
</add>
82
</exceptionTypes>
83
</add>
84
</exceptionPolicies>
85
</exceptionHandling>
86
<cachingConfiguration defaultCacheManager="TiannuoSA.Entities.EntityCache">
87
<cacheManagers>
88
<add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
89
numberToRemoveWhenScavenging="10" backingStoreName="Null Storage"
90
name="TiannuoSA.Entities.EntityCache" />
91
</cacheManagers>
92
<backingStores>
93
<add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
94
name="Null Storage" />
95
</backingStores>
96
</cachingConfiguration>
97
<dataConfiguration defaultDatabase="TiannuoSA.Data.ConnectionString" />
98
<connectionStrings>
99
<add name="TiannuoSA.Data.ConnectionString" connectionString="User ID=;Initial Catalog=;Data Source=;password=" providerName="System.Data.SqlClient" />
100
</connectionStrings>
101![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
102
</configuration>
103![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)