禁用SignalR控制台日志记录。

5

在JavaScript客户端中使用SignalR(后端是ASP.NET Core)。

我想要禁用SignalR的控制台日志记录。基本上,停止这个:

enter image description here

我已经尝试过这样做(但没有任何效果):

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

有人能纠正我吗?

谢谢

3个回答

13

您只需要将以下代码添加到您的代码中.configureLogging(signalR.LogLevel.None),像这样:

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

您可以在Microsoft文档中查看更多日志级别。


谢谢。我已经放进去了,但没有任何改变 :( - Andrew Simpson
非常奇怪,你的意思是你根本不想记录日志...如果你能连接到服务,你会得到任何日志吗? - Kiril1512

1

2022年5月更新:

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

const connection = new HubConnectionBuilder()
    .withUrl()
    .withAutomaticReconnect()
    .configureLogging(LogLevel.None)
    .build();

0
我找到了一种禁用日志记录的方法。
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();

这可能会对某些人有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接