简体   繁体   中英

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. 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. This third party library uses Trace.WriteLine throughout and we would like to stop this from being output to the console.

There doesn't appear to be a global flag to set in app.config to disable all tracing.

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. 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.

Running System.Diagnostics.Trace.Listeners.Clear() after the third party library had loaded solved the issue, nice clean output now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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