Skip to content

Tracing

Jason Curl edited this page Sep 14, 2018 · 2 revisions

TraceSwitch Settings

The SerialPortStream object has a TraceSwitch that you can use to debug your program (or the SerialPortStream itself) if something isn't behaving as you'd expect. The name of the trace source is: IO.Ports.SerialPortStream

To enable tracing, add something similar to below in your App.Config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="IO.Ports.SerialPortStream" switchValue="Verbose">
        <listeners>
          <clear/>
          <add name="myListener"/>
        </listeners>
      </source>
    </sources> 
    <sharedListeners>
      <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="logfile.txt"/>
    </sharedListeners>
  </system.diagnostics>
</configuration>

You should use a switchValue of Warning or less verbosity unless you are debugging your application.

Do not trace to the console. Under the Visual Studio environment, this could bring your application to a halt. Logging to a file uses much less CPU.

Clone this wiki locally