Troubleshooting
If you encounter issues while using the SDK, it is important to troubleshoot with the goal of identifying, analyzing, and resolving any unexpected issues or behaviors. You may encounter problems within the code, and the following two approaches can assist in debugging the problem:
- Debugging using the Logger
- Debugging using metrics
Debugging using the Logger
The SDK supports a file-based logging system, which can be further divided into multiple log levels, such as Informative, Error, and Debug.
- Informative: This is the default log level, which provides limited logs related to execution. Logging at this level records exception logs, but may not provide a complete stack trace.
- Error: The Error logs are more concise and are only created when there is an error.
- Debug: The Debug logs are currently the most verbose and provide enhanced diagnostic information to assist in troubleshooting when errors occur.
You can create an instance of logger by using “Autodesk.DataExchange.Extensions.Logging.File” and the steps for the same are as follows:
- Download and install the package
Autodesk.DataExchange.Extensions.Logging.File
. - Create an instance of a Ilogger by providing the log directory path as a constructor parameter of string type, this will create the instance of the Ilogger.
ILogger Logger = new Log(LogDirectoryPath);
- Set the Debug log level by calling the SetDebugLogLevel() method of the
Autodesk.DataExchange.Extensions.Logging.File
.
Logger.SetDebugLogLevel();
- Enable
Httplog
by calling the EnableHttpDebugLogging() method.
(SDK as Autodesk.DataExchange.Client).EnableHttpDebugLogging();
The default logger of the SDK provides inbuilt Informative
and Error
logs, therefore there is no need to set informative or error log levels explicitly.
Debugging using metrics
The SDK provides access to the Insights.Metrics
class, which enables you to measure various performance metrics of the code.
- You can enable the metrics by using the following method:
Insights.Metrics.EnableMetrics(true);
- To track the time taken for a particular activity you can make use of
StartTracking
andStopTracking
methods.- In the following methods, the input parameter is the name of the activity against which the performance metrics can be calculated.
Insights.Metrics.StartTracking("CreateExchangeAsync").
Insights.Metrics.StopTracking("CreateExchangeAsync").
* Both methods also have one optional parameter `string uniqueid` which can be used to distinguish between two activities with the same name.
Insights.Metrics.StartTracking("CreateExchangeAsync", "q125g49t").
Insights.Metrics.StopTracking("CreateExchangeAsync", "q125g49t").
- To keep the numeric count of an activity, use the following method.
Insights.Metrics.CreateCounter(Id)
- To increment the numeric count of an activity, use the following method.
Insights.Metrics.IncrementCounter(Id)
- To get the data that has been tracked for different operations, use the following method.
Insights.Metrics.GetString();
- To clear all the data inside the metrics class, use the following method.
Insights.Metrics.ClearMetrics()