admin管理员组

文章数量:1221410

using signalR in Javascript client. (backend is asp core).

I want to disable the console logging for signalr. basically, to stop this:

I have done this (but makes no difference):

var connection = new signalR.HubConnectionBuilder().withUrl("./NotificationUserHub").build();
connection.serverTimeoutInMilliseconds = 100000;
connection.logging = false;

someone please correct me?

thanks

using signalR in Javascript client. (backend is asp.net core).

I want to disable the console logging for signalr. basically, to stop this:

I have done this (but makes no difference):

var connection = new signalR.HubConnectionBuilder().withUrl("./NotificationUserHub").build();
connection.serverTimeoutInMilliseconds = 100000;
connection.logging = false;

someone please correct me?

thanks

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Nov 25, 2019 at 11:21 Andrew SimpsonAndrew Simpson 7,32412 gold badges87 silver badges194 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 17

You just need to add this to your code .configureLogging(signalR.LogLevel.None) like this:

var connection = new signalR.HubConnectionBuilder().configureLogging(signalR.LogLevel.None).withUrl("./NotificationUserHub").build();

You can see more log levels in the Microsoft Documentation.

May 2022 update:

import { HubConnectionBuilder, LogLevel } from "@microsoft/signalr";
const connection = new HubConnectionBuilder()
    .withUrl()
    .withAutomaticReconnect()
    .configureLogging(LogLevel.None)
    .build();

I found a way to disable logging.

import { ILogger, LogLevel, HubConnectionBuilder } from "@aspnet/signalr";

export class MyLogger implements ILogger {
    log(logLevel: LogLevel, message: string) {
        // Use `message` and `logLevel` to record the log message to your own system
    }
}

// later on, when configuring your connection...

let connection = new HubConnectionBuilder()
    .withUrl("/my/hub/url")
    .configureLogging(new MyLogger())
    .build();

This might help someone.

本文标签: javascriptDisable signalr console loggingStack Overflow