.NET Based OPC UA Client/Server SDK  3.0.4.468
Trace

Overview

The tracing mechanism built into the SDK can be used by Application Developers in their own code. Application Developers can also provide additional listeners which can capture the trace output. The SDK provides a file based listener and a listener that writes to the debug console in Visual Studio.

The file base listener (the TraceFileListener class) produces a log file with a line like this:

01:02:02.237|0001|02|5|=> Application.CheckConfiguration

Where the fields are: the local time, the thread id, the module id, the trace level and the trace message.

The module id is assigned automatically when a trace module is first used within a process.

Note
The configuration options for the built-in trace functionality can be found in the description of the Configuration Schema, see Trace Settings and Trace Levels.

Creating New Modules

Each Trace Module has a unique name that can be referenced in the TraceSettings element of the Application configuration. This name is defined in code with the TraceModuleInfo class declared in the namespace that is defining the TraceModuleInfo. For example:

public class TraceModuleInfo : UnifiedAutomation.UaBase.TraceModuleInfo
{
public TraceModuleInfo()
{
Name = "Vendor.Client";
}
}

In addition, a trace class which uses this module must be defined as shown here:

public class TraceVendor : TraceBase<TraceModuleInfo>
{
}

At this point all that is required to use this trace module are statements in code like this:

TraceVendor.Error("Something went wrong...");

And the trace module needs to be enabled by adding a line like this to the trace settings:

<ModuleTraceSettings ModuleName="Vendor.Client" TraceEnabled="true" TraceLevel="Data" />

Creating New Listeners

Any class which implements the ITraceListener interface can be registered as a trace listener. A new listener can be registered at any time by calling the TraceBase.AddListener method.

The ITraceListener.Output method is only called if the model is enabled and the trace level is less than or equal to the current trace level for the module.