Logging
The Migration SDK has built-in support for logging. SDK consumers can configure logging levels.NET, Python and add more logging providers (called handlers in Python).NET, Python.
Internally, the SDK will log every successfully Request/Response as an Information message with the Http Request Method, the Http Request Uri and the Http Response Status Code:
> Tableau.Migration.Net.NetworkTraceLogger: Information: HTTP GET "https://localhost/api/2.4/serverinfo" responded "OK".
It will also log every errored Request/Response as an Error message with the Http Request Method, the Http Request Uri and the Error Message:
> Tableau.Migration.Net.NetworkTraceLogger: Error: HTTP GET "https://localhost/api/2.4/serverinfo" failed. Error: "An error occurred while sending the request.".
As part of the included tracings, it is possible to configure the level of details for each log message by setting the following configuration parameters:
- Network.HeadersLoggingEnabled: Indicates whether the SDK logs request/response headers. The default value is disabled.
- Network.ContentLoggingEnabled: Indicates whether the SDK logs request/response content. The default value is disabled.
- Network.BinaryContentLoggingEnabled: Indicates whether the SDK logs request/response binary (not textual) content. The default value is disabled.
- Network.ExceptionsLoggingEnabled: Indicates whether the SDK logs network exceptions. The default value is disabled.
C# Support
The Migration SDK supports logging with built-in or third-party providers such as the ones described in .NET Logging Providers. Refer to that article for guidance in your use case. Some basic examples are below.
Adding your logging provider
You can add logging when you add the Migration SDK to the service collection.
Adding a default provider without configuration
services
.AddTableauMigrationSdk()
.AddLogging();
Adding a logging provider with configuration
This example adds NLog.
services
.AddTableauMigrationSdk()
.AddLogging(builder =>
{
builder.AddNLog();
})
Note
See LoggingServiceCollectionExtensions.AddLogging Method for guidance on how to configure your logging provider.
Python Support
The Migration SDK supports logging with built-in providers like the one described in Python Logging docs.
SDK default handler
The SDK adds a StreamHandler to the root logger by executing the following command:
logging.basicConfig(
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level = logging.INFO)
Overriding default handler configuration
To override the default configuration, the parameter force
must be set to True
.
logging.basicConfig(
force = True,
format = '%(asctime)s|%(levelname)s|%(name)s -\t%(message)s',
level = logging.WARNING)
Note
See Logging Configuration for advanced configuration guidance.