Every so often I find that I have accidentally broken data binding in my application. Either by renaming a property and not renaming it in the XAML or by a property throwing an exception for some reason.
By default data binding errors are logged to debug output and exceptions that are thrown are caught and suppressed.
Is there an easy way to have an exception thrown after the debug output is logged?
I want to know as soon as possible if data binding is broken (ideally picking it up in an automated test) and not risk the chance that it might go unnoticed until tested by a human.
After some procrastination I finally set about coding a solution to my original issue.
My solution uses a custom
TraceListener(originally suggested by John) that logs to an output window. The output window is automatically displayed and bought to the foreground when an error occurs.Here is my
TraceListener:TraceListeneris defined in System.Diagnostics.The custom
TraceListenermust be hooked into the system to be used. The official way to do this is to set something in the registry and then use theApp.configfile to configure theTraceListener.However I found that there is a much easier way to do this programmatically:
PresentationTraceSourcesis also defined inSystem.Diagnostics.For more information on trace sources see Mike Hillberg’s blog.
Bea Stollnitz has some useful info on her blog.