2011-06-22 27 views
1

我在修改傳統的asp.net項目。我想包括一些名稱空間,類和方法的透明日誌記錄。用EntLib在ASP.NET中透明記錄

我使用EntLib。我可以配置警察注射設置以透明地記錄我的應用程序嗎我必須做什麼才能將所有方法記錄在指定的命名空間中?

它是我的web.config的一部分。

<policyInjection> 
<policies> 
    <add name="Policy"> 
    <matchingRules> 
     <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.NamespaceMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     name="Namespace Matching Rule"> 
     <matches> 
      <add match="MyNamespace.*" ignoreCase="true" /> 
     </matches> 
     </add> 
    </matchingRules> 
    <handlers> 
     <add type="Microsoft.Practices.EnterpriseLibrary.Logging.PolicyInjection.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     beforeMessage="+++AOP " afterMessage=" AOP+++" name="Logging Call Handler"> 
     <categories> 
      <add name="General" /> 
     </categories> 
     </add> 
    </handlers> 
    </add> 
</policies> 

+0

任何人有反應 –

回答

0

你使用Unity創建和myNameSpace對象注入類?如果是這樣,請嘗試在映射部分添加一個元素。

<type type="IMyService" mapTo="MyService"> 
    <lifetime type="singleton"/> 
    <interceptor type="InterfaceInterceptor"/> 
    <policyInjection/> 
</type> 

您還需要添加此此sectionExtension登記:

<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration"/>