The .net-sdk can be configured to emit very detailed debugging and diagnostic information to a log file during execution. The .net-sdk uses the standard .NET System.Diagnostic infrastructure for Logging, as such, all configuration of the .net-sdk logger is done via the standard .NET Logging configuration system.

 

  • By default, Logging is configured via the standard .NET “App.config” file.
  • Log messages can be routed to any standard .NET TraceListener. Optionally, ThingWorx provides a FixedFieldTraceListener which can be used to output log messages to a file. The use of the ThingWorx provided FixedFieldTraceListener is recommended.
    • The FixedFieldTraceListener when configured will automatically create a "logs" directory in the same location as (a sibling to) the running executable file (.exe). This "logs" directory will contain the log files.
  • Every .NET Class can be configured as a specific “Trace Source” which emits log messages. It is recommended to add at least the following Trace Sources to your App.config file to receive the most useful amount of information:

 

    • com.thingworx.communications.client.BaseClient
    • com.thingworx.communications.client.ConnectedThingClient
    • com.thingworx.communications.client.things.VirtualThing
    • com.thingworx.communications.client.TwApiWrapper
    • com.thingworx.communications.client.things.filetransfer.FileTransferVirtualThing
    • com.thingworx.communications.client.things.contentloader.ContentLoaderVirtualThing

 

The amount of information emitted can range from very low level Trace messages (the Verbose setting) to nothing at all (the Off setting). The “SourceLevels Enumeration” can be used to control how much information is written out to the log file. For reference, this is the

<add name="SourceSwitch" value="Information" /> element in the sample below.

 

 

Below is sample App.config file.

 

<?xml version="1.0" encoding="utf-8"?>

<configuration>

    <system.diagnostics>

      <sources>

        <source name="com.thingworx.common.utils.JSONUtilities" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.communications.client.TwApiWrapper" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.communications.client.BaseClient" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.communications.client.ConnectedThingClient" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.communications.client.things.contentloader.ContentLoaderVirtualThing" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.communications.client.things.filetransfer.FileTransferVirtualThing" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.communications.client.things.VirtualThing" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

        <source name="com.thingworx.metadata.annotations.MetadataAnnotationParser" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >

          <listeners>

            <add name="file" />

          </listeners>

        </source>

      </sources>

      <switches>

        <add name="SourceSwitch" value="Information" />

      </switches>

      <sharedListeners>

        <add name="file" type="com.thingworx.common.logging.FixedFieldTraceListener, thingworx-dotnet-common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" initializeData="false"/>

      </sharedListeners>

      <trace autoflush="true" indentsize="4" />

  </system.diagnostics>

</configuration>