Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After some procrastination I finally set about coding a solution to my original issue.</p> <p>My solution uses a custom <code>TraceListener</code> (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.</p> <p>Here is my <code>TraceListener</code>:</p> <pre><code>public class ErrorLogTraceListener : TraceListener { public override void Write(string message) { ... } public override void WriteLine(string message) { ... } } </code></pre> <p><code>TraceListener</code> is defined in System.Diagnostics.</p> <p>The custom <code>TraceListener</code> must be hooked into the system to be used. The official way to do this is to set something in the registry and then use the <code>App.config</code> file to configure the <code>TraceListener</code>. </p> <p>However I found that there is a much easier way to do this programmatically:</p> <pre><code>ErrorLogTraceListener listener = new ErrorLogTraceListener(); PresentationTraceSources.Refresh(); PresentationTraceSources.DataBindingSource.Listeners.Add(listener); PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error; </code></pre> <p><code>PresentationTraceSources</code> is also defined in <code>System.Diagnostics</code>.</p> <p>For more information on trace sources see Mike Hillberg's <a href="http://blogs.msdn.com/mikehillberg/archive/2006/09/14/WpfTraceSources.aspx" rel="nofollow noreferrer">blog</a>.</p> <p>Bea Stollnitz has some useful info on her <a href="http://www.beacosta.com/blog/?p=52" rel="nofollow noreferrer">blog</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload