简体   繁体   English

禁用C#控制台应用程序中的跟踪,包括第三方引用

[英]Disable tracing in C# Console Application including third party references

We have a C# Console Application that triggers PowerShell using the classes in the System.Management.Automation assembly. 我们有一个C#控制台应用程序,它使用System.Management.Automation程序集中的类来触发PowerShell。 The PowerShell script references a third party library (the library is imported using Import-Module within the script that executes) that performs execution within the PowerShell script. PowerShell脚本引用第三方库(使用执行的脚本中的Import-Module导入库),该脚在PowerShell脚本中执行。 This third party library uses Trace.WriteLine throughout and we would like to stop this from being output to the console. 这个第三方库始终使用Trace.WriteLine,我们希望阻止它输出到控制台。

There doesn't appear to be a global flag to set in app.config to disable all tracing. 似乎没有在app.config中设置全局标志来禁用所有跟踪。

The system.diagnostics element is set with a source with no listeners, a trace with no listeners, and no switches but the output is still being written to the console. system.diagnostics元素设置为没有侦听器的源,没有侦听器的跟踪,没有开关但输出仍然写入控制台。 How can all tracing be disabled? 如何禁用所有跟踪?

Thanks to @CodeCaster for the pointer, it was in fact that the listener was being added by the third party library so the app.config settings had no effect. 感谢@CodeCaster指针,实际上是第三方库添加了监听器,因此app.config设置无效。

Running System.Diagnostics.Trace.Listeners.Clear() after the third party library had loaded solved the issue, nice clean output now. 在第三方库加载后运行System.Diagnostics.Trace.Listeners.Clear()解决了问题,现在很好的干净输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM