Author:
水如烟
日志的实现:
MethodLogAttribute.vb
Namespace
uRemoting.MethodWatcher
<
AttributeUsage(AttributeTargets.Class)
>
_
Public
Class
MethodLogAttribute
Inherits
MethodWatcherBaseAttribute
Protected
Overrides
Function
GetMethodWatcherProperty()
As
MethodWatcherBaseProperty
Return
New
MethodLogProperty
End Function
End Class
End Namespace
MethodLogProperty.vb
Namespace
uRemoting.MethodWatcher
Public
Class
MethodLogProperty
Inherits
MethodWatcherBaseProperty
Protected
Overrides
Function
CreateSink(
ByVal
nextSink
As
System.Runtime.Remoting.Messaging.IMessageSink)
As
System.Runtime.Remoting.Messaging.IMessageSink
Return
New
MethodLogSink(nextSink)
End Function
End Class
End Namespace
MethodLogSink.vb
Imports
System.Runtime.Remoting.Messaging
Namespace
uRemoting.MethodWatcher
Public
Class
MethodLogSink
Inherits
MethodWatcherBaseSink
Sub
New
(
ByVal
nextSink
As
IMessageSink)
MyBase
.New(nextSink)
End Sub
Protected
Overrides
ReadOnly
Property
MethodWatcherAppendAttributeType()
As
System.Type
Get
Return
GetType
(MethodLogAppendAttribute)
End
Get
End Property
End Class
End Namespace
MethodLogAppendAttribute.vb
Namespace
uRemoting.MethodWatcher
<
AttributeUsage(AttributeTargets.Class, allowmultiple:
=
True
)
>
_
Public
NotInheritable
Class
MethodLogAppendAttribute
Inherits
MethodWatcherAppendBaseAttribute
Sub
New
(
ByVal
methodName
As
String
)
MyBase
.New(methodName)
End Sub
End Class
End Namespace
MethodLogCenter.vb
Imports
System.Runtime.Remoting.Messaging
Namespace
uRemoting.MethodWatcher
Public
Class
MethodLogCenter
Inherits
MethodWatcherCenter
Public
Sub
Ready()
Remove()
AddHandler
MethodCallBegin,
New
BeforeMethodCallHandle(
AddressOf
WriteMethodCallBegin)
AddHandler
MethodCallOver,
New
AfterMethodCallHandle(
AddressOf
WriteMethodCallOver)
End Sub
Public
Sub
Remove()
RemoveHandler
MethodCallBegin,
New
BeforeMethodCallHandle(
AddressOf
WriteMethodCallBegin)
RemoveHandler
MethodCallOver,
New
AfterMethodCallHandle(
AddressOf
WriteMethodCallOver)
End Sub
Private
Sub
WriteMethodCallBegin(
ByVal
callMsg
As
IMethodCallMessage,
ByVal
MethodAppendType
As
System.Type)
If
MethodAppendType.Equals(
GetType
(MethodLogAppendAttribute))
Then
Console.WriteLine(
"
{0}({1},{2})
"
, callMsg.MethodBase.DeclaringType.FullName
+
"
+
"
+
callMsg.MethodName, callMsg.GetArg(
0
), callMsg.GetArg(
1
))
Else
Console.WriteLine(
"
MethodOtherBeing:
"
+
MethodWatcherCommon.GetFullMethodName(callMsg, MethodAppendType))
End
If
End Sub
Private
Sub
WriteMethodCallOver(
ByVal
replyMsg
As
IMethodReturnMessage,
ByVal
MethodAppendType
As
System.Type)
If
MethodAppendType.Equals(
GetType
(MethodLogAppendAttribute))
Then
Console.WriteLine(
"
{0} Result is {1}
"
, replyMsg.MethodBase.DeclaringType.FullName
+
"
+
"
+
replyMsg.MethodName, replyMsg.ReturnValue)
Else
Console.WriteLine(
"
MethodOtherOver:
"
+
MethodWatcherCommon.GetFullMethodName(replyMsg, MethodAppendType))
End
If
End Sub
End Class
End Namespace