Core SignalR message sizes - is there a way to log how large your messages are?

Viewed 173

I've read through the documentation and it seems like there is no built in way to measure the size of messages going out/coming in through SignalR. I have a very large amount of messages being sent out, and bandwidth can become an issue.

What I want to be able to do is run the SignalR server for a day and see how much data is transferred in total.

Does anyone know of a workaround to log this?

1 Answers

Looks like I can get message size in the debug level logging. Here is how you add that for anyone who might have the same issue.

Connection = new HubConnectionBuilder()
        .WithUrl(Url, options =>
        {
            options.AccessTokenProvider = () => Task.FromResult(tokenString);
        })
        .AddMessagePackProtocol()
        .ConfigureLogging(logging =>
        {
            // Log to the Console
            logging.AddConsole();

            // Set to debug or trace
            logging.SetMinimumLevel(LogLevel.Trace); 
        })
        .WithAutomaticReconnect()
        .Build();
Related