I wouldn't recommend it. The problem is that Debug.Assert
is only supposed to be fired when you have bugs in your code. If you just ignore them or don't fix them, then you are doing your users a disservice. If, on the other hand, you're firing Debug.Assert
for things that aren't bugs, then you're also doing your users a disservice (by reducing the impact of Debug.Assert).
Having said that, you can disable it. The first thing you need to do is remove the default listener from the Debug.Listeners collection:
Debug.Listeners.Clear();
Then, add your own instead:
Debug.Listeners.Add(new MyTraceListener());
You need to create a class that inherits from TraceListener:
class MyTraceListener : TraceListener
{
// ...
public override void Fail(string msg, string detailedMsg)
{
// log the message (don't display a MessageBox)
}
}
The important method is the TraceListener.Fail method, which in the implementation of DefaultTraceListener
is what displays the message box.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…