阻止来自外部包的.NET控制台日志记录。

huangapple go评论84阅读模式
英文:

Prevent console logging from external package .NET

问题

我们正在使用一个外部包(Microsoft.Azure.Kusto.Data),它正在向控制台输出大量日志。我们正在使用控制台日志提供程序,它会将所有写入控制台的内容都存储起来。这个包似乎没有使用记录器,可能是直接使用 Console.WriteLine 或类似的方式写入控制台,因此更改日志级别无法帮助。

有没有办法阻止特定的包向控制台输出?

下面是在 appsettings.json 中添加到 loglevel 的内容,但没有起作用:

"Microsoft.Azure.Kusto.Data": "Warning"

虽然对其他包有效。

英文:

We're using an external package (Microsoft.Azure.Kusto.Data) which is clogging up the console with tons of logs. We are using console logging provider and stores everything that's written to console. The package doesn't seem to use a logger, it's probably more directly writing to console with Console.WriteLine or similar, so changing log level doesn't help.

Is there a way to prevent a specific package to output to console?

Here's a screenshot from the logging in vs code,the two upper logs (starting with P.*) are from the kusto package while the other two (tagged with info) are our own logs.

阻止来自外部包的.NET控制台日志记录。

Adding this to loglevel in appsettings.json did nothing:

"Microsoft.Azure.Kusto.Data": "Warning"

While it worked for other packages.

答案1

得分: 0

这似乎部分原因是由Azure Data Explorer Tracing引起的,添加以下代码片段可以消除大部分日志:

using Kusto.Cloud.Platform.Utils;

...

TraceSourceManager.SetTraceVerbosityForAll(TraceVerbosity.Error);

尽管在连接时仍会收到来自“Tweaks”的日志:

阻止来自外部包的.NET控制台日志记录。

但这只会发生一次,所以我可以暂时接受。

英文:

This seems to (partially) be caused by Azure Data Explorer Tracing and adding this snippet got rid of most of the logs:

using Kusto.Cloud.Platform.Utils;

...

    TraceSourceManager.SetTraceVerbosityForAll(TraceVerbosity.Error);

Though I still get logs from "Tweaks" when connecting:

阻止来自外部包的.NET控制台日志记录。

That only happens once so I can live with that for now.

huangapple
  • 本文由 发表于 2023年1月9日 16:17:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定