Ably Pub/Sub Realtime ILoggerSink LogEvent not working

102 views Asked by At

I am using VB.NET with Ably .NET Realtime library version 1.2.1. I have a wrapper class setting up and managing Ably. The class implements ILoggerSink. It is setting up the channel as shown by these snippets from different parts of the class:

Public Class Ably
    Implements IDisposable, ILoggerSink
.
.
Private WithEvents mChannel As IRealtimeChannel
Private Delegate Sub ReceiveMessageDelegate(ByVal m As Message)
Private Delegate Sub PublishCallbackDelegate(ByVal result As Boolean, ByVal einfo As ErrorInfo)
Private mPublishCallbackDelegate As PublishCallbackDelegate = AddressOf PublishCallback
Private mReceiveMessageDelegate As ReceiveMessageDelegate = AddressOf ReceiveMessage
.
.
Dim opt = New ClientOptions(Main.AblyConnectionKey) With {.EchoMessages = False, .LogLevel = LogLevel.Debug}
Dim art = New AblyRealtime(opt)
mChannel = art.Channels.Get(idstr)
mChannel.Subscribe(Sub(m) mReceiveMessageDelegate(m))
.
.
mChannel.Publish(mname, mdata, Sub(m, n) mPublishCallbackDelegate(m, n))

The interface method starts with this definition:

Public Sub LogEvent(level As LogLevel, message As String) Implements ILoggerSink.LogEvent
'The rest of the sub here.

All of the other Ably things managed by this class work - attaching to the channel, publishing messages and receiving messages. The class gets mChannel.StateChanged and mChannel.[Error] events.

The LogEvent method never gets called. What am I missing? Thanks.

Update: The accepted answer worked and was a simple thing I missed seeing in any documentation. Here is the corrected line of code:

Dim opt = New ClientOptions(Main.AblyConnectionKey) With {.EchoMessages = False, .LogLevel = LogLevel.Debug, .LogHander = Me}

Also deemed noteworthy is that this class is a singleton.

1

There are 1 answers

0
marto On BEST ANSWER

The missing piece is that you need to tell the library which LoggerSink to use.

Something like Logger.LoggerSink = Me.

You need to be careful because the ably Logger is static and there is only once instance for the whole program. It will be a problem if you are going to instantiate more than one instance of you Ably class.

Generally it's recommended to have 1 instance of the RealtimeClient anyway so you will probably be Ok with the above code.