Logging with SignalR
in this post I’ll briefly show how to enable this log, what it
writes when enable, and how to add some custom log records.
To enable logging you simply need to add the following
After enabling the log you’ll see what client events were
triggered by the server.
For example, when you call in your Hub code (server side) you
call Clients.All.sendMessage, this is what you’ll see on your
console tab (taken from Chrome console)
[12:02:21 GMT+0200 (Jerusalem Standard Time)] SignalR: Triggering client hub event ‘sendMessage’ on hub ‘chatHub’.
Apart from simply using the console.log() function, you
can use the $.connection.hub.log() function provided
by signalR. This function won’t do anything if logging
is disabled, end write to the console log if enabled.
Let’s see an example:
In the following code example we call sever side’s chat method
and log our call write away.
And this is what we’ll see on our console:
[12:59:08 GMT+0200 (Jerusalem Standard Time)] SignalR: Sending Hi fellows to the server
signalR logging is simple yet very handy tool to monitor our application
at development time. You may find it useful and all you have to do
when going to production is to disable the log.