Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在内置跟踪侦听器(例如System.Diagnostics.DefaultTraceListener和)上使用过滤System.Diagnostics.TextWriterTraceListener?
System.Diagnostics.DefaultTraceListener
System.Diagnostics.TextWriterTraceListener
我不想重写 write 方法并显式检查过滤,但是我找不到将级别附加到跟踪信息的方法?
您可以使用跟踪开关进行一些过滤。在您的配置文件中添加一个跟踪开关,然后将级别设置为 0、1、2、3 或 4(分别表示关闭、错误、警告、信息、详细)。然后,您将使用 WriteLineIf(traceSwitch.Error, ....) 仅在跟踪开关配置为错误时打印,如果跟踪开关设置为错误或警告,则使用 WriteLineIF(traceSwitch.Warning, ...) 打印, ETC...