1
即時通訊嘗試創建一個帶有Microsoft Unity和AOP的記錄器,但有些東西不起作用......我不明白..我只知道我不記錄任何東西。用Unity和AOP創建一個日誌
這裏記錄器的代碼:
public class LoggerHandler : ICallHandler
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
//The code to write a file
return result;
}
...
}
在這裏,我創建屬性:
//create an attribute so you can apply it to your methods
public class LoggerAttribute : Attribute
{
public LoggerAttribute()
{
//Here I have a breakpoint just to understand if i go here. I never stop here
}
}
這裏的幫手通過的web.config配置攔截
public class GetTypeConverter : TypeConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return Type.GetType(value.ToString());
}
}
而且這裏web.config
<types>
<type type="en.MFS.BLL.Countries.ICountries, en.MFS.BLL.Countries"
mapTo="en.MFS.BLL.France.FranceBLL, en.MFS.BLL.France">
<interceptor type="TransparentProxyInterceptor" />
</type>
</types>
<extension type="Interception" />
<interception>
<policy name="LoggerPolicy">
<matchingRule name="TransactionMatchingRule" type="CustomAttributeMatchingRule">
<constructor>
<param name="attributeType" type="System.Type">
<value value="en.MFS.LoggerInterception.LoggerAttribute" typeConverter="en.MFS.LoggerInterception.GetTypeConverter, en.MFS.LoggerInterception"/>
</param>
<param name="inherited" value="true" />
</constructor>
</matchingRule>
<callHandler name="LoggerHandler"
type="en.MFS.LoggerInterception.LoggerHandler, en.MFS.LoggerInterception" >
<property name="Order" value="1" />
</callHandler>
</policy>
</interception>
而在最後,我如何使用它
[Logger]
GetCalculation_OutDTO GetCalculation(GetCalculation_InDTO calculationDTO);
那麼,什麼是錯的?爲什麼我不設法進入LoggerAttribute的構造函數?