2014-09-29 126 views
0

我有一個AutoLogExceptionAspect類及其結成夥伴的事件源,AutoLogExceptionEventSource,就像如下:如何使用自定義事件偵聽器與PostSharp方面

<Serializable()> 
Public Class AutoLogExceptionAspect 
    Inherits OnExceptionAspect 
    Public Overrides Sub OnException(ByVal args As MethodExecutionArgs) 
     AutoLogExceptionEventSource.Log.LogException(args.Exception.GetType().Name, args.Exception.Message, args.Exception.StackTrace) 
     args.FlowBehavior = FlowBehavior.Continue 
    End Sub 
End Class 

<EventSource(Name:=EventSourceNames.AutoLogException)> 
Public NotInheritable Class AutoLogExceptionEventSource 
    Inherits EventSource 
    Public Class Tasks 
     Public Const MethodExecution As EventTask = CType(1, EventTask) 
    End Class 
    Private Const ExceptionLog As Integer = EventIdBases.AutoLogException + 1 
    Private Const MethodExecution As Integer = CType(1, EventTask) 
    Private Shared ReadOnly Instance As Lazy(Of AutoLogExceptionEventSource) = New Lazy(Of AutoLogExceptionEventSource)(Function() New AutoLogExceptionEventSource()) 
    Public Shared ReadOnly Property Log As AutoLogExceptionEventSource 
     Get 
      Return Instance.Value 
     End Get 
    End Property 
    <[Event](ExceptionLog, Level:=EventLevel.Error, Task:=MethodExecution, Opcode:=EventOpcode.Info)> 
    Public Sub LogException(exceptionType As String, message As String, stackTrace As String) 
     If (IsEnabled()) Then 
      WriteEvent(ExceptionLog, exceptionType, message, stackTrace) 
     End If 
    End Sub 
End Class 

我也有一個RollingLogFileTraceListener的TraceListenerFileLogTraceListener衍生,在ctor中有一些cusatom設置。現在我不知道如何將這個聽衆與我的EventSource類聯繫起來。我不想用我的Windows事件日誌填充大量異常粘連痕跡。如何將RollingLogFileTraceListener與我的AutoLogExceptionEventSource一起使用?

回答

相關問題