Turning tracing off via app.config

后端 未结 6 1944
孤独总比滥情好
孤独总比滥情好 2020-12-08 05:20

I\'m trying to use System.Diagnostics to do some very basic logging. I figure I\'d use what\'s in the box rather than taking on an extra dependency like Log4Net or EntLib. <

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 05:47

    You don't turn off tracing globally this way.

    You have to
    1) declare a switch and set its value:

    
      
    
    

    2) associate this switch with a TraceSource you use:

    
      
    
    

    So, whatever you write via TraceSource named "MySource" is filtered according to the switch value.

    If you use static methods like Trace.Write, I suppose, you cannot use switches at all, because there is no TraceSource to apply the filter.
    If you want to turn off tracing by static methods, just remove all the listeners: .

提交回复
热议问题