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

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-09-17
  • 2021-06-20
猜你喜欢
  • 2021-12-07
  • 2022-03-04
  • 2021-08-14
  • 2021-09-15
  • 2021-09-29
  • 2021-09-21
  • 2022-01-29
相关资源
相似解决方案