Error handling - Enable Tracing

This article is relevant for all .Net products

The Use of Status Codes in the SDK
All functions that may encounter errors during execution use the enumeration EnumStatusCode to specify the error condition. The values of the StatusCode enumeration are defined by the OPC Foundation and are also used to denote errors in service calls. Also the quality of a variable's value is denoted by the same StatusCode. See the reference manual to receive the complete list of all enumeration values.
The SDK provides the global function getEnumStatusCodeString() to retrieve the textual description of a StatusCode. This method can be useful for debugging error conditions.
The StatusCode class provides convenience methods for testing status codes. The static method StatusCode::isGood(), for example, may be used to test whether a given status code is 'good', i.e. does not indicate an error.

Enabling Tracing for the SDK Components
If a status code does not provide enough information to identify a problem, you may turn on tracing of diagnostic messages. Tracing of diagnostic messages can be enabled in the Trace singleton class. The following code illustrates how to enable tracing to a log file:
Trace::instance()->enableFileLogging(_T("logging.txt"), 10000, 5, 256);
Trace::instance()->enableTraceLevel(EnumTraceGroup_All, EnumTraceLevel_WarningAndHigher);
The trace output can also be streamed over a TCP connection. See the Trace Viewer topic for further reference.
It is also possible to implement an individual tracing. To do this, invoke the Trace::enableCallbackLogging(). The given callback will be invoked on every enabled trace level / trace group.