logo
logo

Diagnostics

The Web SDK also includes a diagnostics client. This can be useful for auditing and/or debugging.

The diagnostics client is static and will be shared along all IWebMClient instances.

Supported diagnostics

The diagnostics client supports the following features:

  • Setting a (custom) logger where all entries will be logged to
  • Logging HTTP requests and responses. This can be set to:

    • None: no HTTP requests and responses will be logged
    • Minimal: only the request method, request URL and the response status code will be logged.
    • Full: full log of the requests and responses, including their payload.
  • Logging caching events: e.g. when an entry was added or removed from the cache

  • Logging resilience events: e.g. timeouts, retries, throttling...
  • Logging warnings: when the SDK notices unexpected behaviour

Setting up logging

To enable logging it is required to set a logger on the DiagnosticsClient. It is possible to set any ILogger implementation. The ConsoleLogger is an out-of-the-box ILogger implementation that writes to the console. The ConsoleLogger can be found under the stylelabs.M.Sdk.Models.Logging namespace.

Be sure to set the log level to debug, because most of the entries will be logged under debug.

The DiagnosticsClient can be found under the Stylelabs.M.Sdk.WebClient.Diagnostics namespace.

DiagnosticsClient.Logger = new ConsoleLogger
{
        MinimumLogLevel = LogLevel.Debug
};

DiagnosticsClient.HttpLogging = HttpLogging.Full;

Logging HTTP requests and responses example

In the following example an Asset entity is fetched from a newly created client with HTTPLogging set to Full.

var entity = await MClient.Entities.GetAsync(9071);

This will result in the following requests and responses:

Request 1: authenticating using OAuth

19/12/2018 13:34:02 | Debug | Http request:
        Method: POST
        Uri: https://{instance_url}/oauth/token
        Headers:
                Accept: application/json

        Content: grant_type=password&client_id=redacted&client_secret=redacted&username=redacted&password=redacted

Response 1: authenticating using OAuth

19/12/2018 13:34:03 | Debug | Http response:
        Status: OK (200)
        Headers:
                Cache-Control: no-cache
                Pragma: no-cache
                Server:
                X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcU3R5bGVMYWJzXHN0eWxlbGFicy5tXHNyY1xTdHlsZWxhYnMuTS5Qb3J0YWwuV2ViLlVJXG9hdXRoXHRva2Vu?=
                X-Content-Type-Options: nosniff
                Date: Wed, 19 Dec 2018 12:34:03 GMT

        Content: {"access_token":"3iWzO6LgQ9g72wvOs4BO7qtAGx7zkBgtmTlvAoL4a7TXMdUKaej13QOqTy_qRBZqACaKFoWBNwCXYL4JKDNor18GGeQfdQ_vk1yk7iHwGVRCgIvfJ2YqhnKAPek3QD6qbG4oRhpsrZUkyZUB6RAcKFZ93xaExWYd_JJ5vGtQCF6_LoyXyP5TG6O0JToITpzLAclYyUDZ2-HZKIZFITsc5lXj38KsDWrVcpZVCyjh86l4KoTYGtRbZmZryMX9TPhT","token_type":"bearer","expires_in":3599,"refresh_token":"JFoga8bwSv7BSuNyI49_pqVMGtFfnCJhHanxWUXgml7_-9-HdMa-JsVQ5xLI2-2CmXjs91u_Uj6OMK6Mdft2LhkP4-6GwOt8W0vhPOwyvb_Vg-_70MaqCaf_B1bpnJem04inUZaRI-YccZdlW82Pii6WlMEz0B3la4mi1pZJ9W2Ab4wMf_PbHjxXOZFxHkhJVLRyOr2mLzF47C0QevJoYkZxk_mbPv90usfVmAZYGU2UDTn1SZCI3xvbvqvKpQnYuwqwBiSflc1E5MQt40NwRA"}

Request 2: getting the API information

19/12/2018 13:34:03 | Debug | Http request:
        Method: GET
        Uri: https://{instance_url}/api
        Headers:
                X-ApiVersion: 2
                Accept: application/json
                Authorization: Bearer 3iWzO6LgQ9g72wvOs4BO7qtAGx7zkBgtmTlvAoL4a7TXMdUKaej13QOqTy_qRBZqACaKFoWBNwCXYL4JKDNor18GGeQfdQ_vk1yk7iHwGVRCgIvfJ2YqhnKAPek3QD6qbG4oRhpsrZUkyZUB6RAcKFZ93xaExWYd_JJ5vGtQCF6_LoyXyP5TG6O0JToITpzLAclYyUDZ2-HZKIZFITsc5lXj38KsDWrVcpZVCyjh86l4KoTYGtRbZmZryMX9TPhT

        Content: none

Response 2: getting the API information

19/12/2018 13:34:03 | Debug | Http response:
        Status: OK (200)
        Headers:
                Cache-Control: no-store
                ETag: "2NRWHN9w1W1JrR4sgNt+ew8at/N1pOSYGGOCYHR8aik="
                Server:
                X-Frame-Options: DENY
                X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcU3R5bGVMYWJzXHN0eWxlbGFicy5tXHNyY1xTdHlsZWxhYnMuTS5Qb3J0YWwuV2ViLlVJXGFwaQ==?=
                X-Content-Type-Options: nosniff
                Date: Wed, 19 Dec 2018 12:34:03 GMT

        Content: {"file_version":"1.0.0.0","product_version":"1.0.0.0","minimum_sdk_version":"3.0.0.0","routes":{"action_status":{"href":"https://{instance_url}/api/action/status/{action}","title":"Get Action Health Status","templated":true},"agent_by_id":{"href":"https://{instance_url}/api/agents/{id}","title":"Gets the Media Processing Agent By Id","templated":true},"agents":{"href":"https://{instance_url}/api/agents","title":"An overview of all connected Media Processing Agents"},"aggregates":{"href":"https://{instance_url}/api/aggregates/{name}/{id}{?culture,loadPermissions}","title":"The specified aggregate for the specified entity.","templated":true},"allsavedselections":{"href":"https://{instance_url}/api/savedselections{?fullText,skip,take,sort,order,sortCulture}","title":"Your saved selections.","templated":true},"audit":{"href":"https://{instance_url}/api/audit","title":"Get audit api info"},"authenticate":{"href":"https://{instance_url}/api/authenticate/{userName}","title":"Provides authentication tokens","templated":true},"breadcrumbs_by_id":{"href":"https://{instance_url}/api/breadcrumbs/{id}?culture={culture}","title":"Get the breadcrumbs with the specified id.","templated":true},"cache":{"href":"https://{instance_url}/api/cache/{name}","title":"Clear cache","templated":true},"change_password":{"href":"https://{instance_url}/api/account/changepassword","title":"Changes the password of the logged on user.","templated":true},"checkouts":{"href":"https://{instance_url}/api/checkouts","title":"Your checkouts"},"chili":{"href":"https://{instance_url}/api/chili","title":"Chili publish integration links"},"colorprofiles":{"href":"https://{instance_url}/api/colorprofiles","title":"Get identifier and title for all color profiles."},"commands":{"href":"https://{instance_url}/api/commands/{folder}/{command}","title":"Execute a command","templated":true},"compile_script":{"href":"https://{instance_url}/api/scripts/{scriptContentId}/compile","title":"Compile a script","templated":true},"conditional_members":{"href":"https://{instance_url}/api/conditionalmembers","title":"Renders the conditional members of an entity-definition."},"datasource_by_name":{"href":"https://{instance_url}/api/datasources/{name}","title":"Gets a datasources by name","templated":true},"datasources":{"href":"https://{instance_url}/api/datasources","title":"Gets the names of all datasources","templated":true},"default_theme":{"href":"https://{instance_url}/api/theme","title":"Get the current default theme information"},"descendants_by_query":{"href":"https://{instance_url}/api/entities/descendants","title":"Descendants by query"},"download_orders":{"href":"https://{instance_url}/api/downloadorders","title":"Your download orders."},"download_orders_by_id":{"href":"https://{instance_url}/api/downloadorders/{id}","title":"Gets the download order with the specified id","templated":true},"entities":{"href":"https://{instance_url}/api/entities","title":"Your entities"},"entities_by_definition":{"href":"https://{instance_url}/api/entitydefinitions/{name}/entities{?skip,take,culture,members,nestedRelations}","title":"Get the entities with the specified definition name","templated":true},"entities_by_query":{"href":"https://{instance_url}/api/entities/query{?query,skip,take,members,renditions,culture,sort,order,sortCulture,nestedRelations}","title":"Entities by query","templated":true},"entities_by_scroll":{"href":"https://{instance_url}/api/entities/scroll{?query,identifier,take,members,renditions,culture,sort,order,sortCulture,nestedRelations}","title":"Entities by scroll","templated":true},"entity_by_id":{"href":"https://{instance_url}/api/entities/{id}{?culture,members,groups,renditions,nestedRelations,loadPermissions}","title":"Get the entity with the specified id","templated":true},"entity_by_identifier":{"href":"https://{instance_url}/api/entities/identifier/{identifier}{?culture,members,groups,renditions,nestedRelations,loadPermissions}","title":"Get the entity with the specified identifier","templated":true},"entity_relation_by_name":{"href":"https://{instance_url}/api/entities/{id}/relations/{name}{?id,name}","title":"Get the relation of with the specified name on the specified entity","templated":true},"entitydefinition_by_name":{"href":"https://{instance_url}/api/entitydefinitions/{name}{?includeConditionalMembers,loadPermissions}","title":"Get the entity with the specified name","templated":true},"entitydefinitions":{"href":"https://{instance_url}/api/entitydefinitions{?skip,take,filter,definitionsToLoad,viewMode,loadPermissions,includeConditionalMembers,excludeTaxonomyDefinitions,excludeSystemOwnedDefinitions}","title":"Your entity definitions","templated":true},"execute_script":{"href":"https://{instance_url}/api/scripts/{identifier}/execute","title":"Execute an action script by script identifier","templated":true},"explain_permissions":{"href":"https://{instance_url}/api/entities/{id}/permissions/{userId}","title":"Explains user's permissions for the specified entity","templated":true},"fetchjobs":{"href":"https://{instance_url}/api/fetchjobs{?skip,take}","title":"Your fetch jobs.","templated":true},"fetchjobs_by_id":{"href":"https://{instance_url}/api/fetchjobs/{id}","title":"Get the fetch job with the specified id.","templated":true},"gateway_by_id":{"href":"https://{instance_url}/api/gateway/identifier/{identifier}/{rendition}","title":"Gateway by Id"},"gateway_by_identifier":{"href":"https://{instance_url}/api/gateway/identifier/{identifier}/{rendition}","title":"Gateway by Identifier"},"generate_by_id":{"href":"https://{instance_url}/api/print/publication/{id}?culture={culture}&quality={quality}&save={save}","title":"Generate a publication with the specified id, culture and quality","templated":true},"generate_oauth_token":{"href":"https://{instance_url}/api/account/{userId}/generateoauthtoken","title":"Generates an OAuth token for the specified user.","templated":true},"generate_public_link":{"href":"https://{instance_url}/api/public","title":"Generate a public link."},"impersonate":{"href":"https://{instance_url}/api/account/{userId}/impersonate","title":"Impersonate another user.","templated":true},"log_script":{"href":"https://{instance_url}/api/scripts/{scriptContentId}/log{?skip,take,sorting}","title":"Get log from a ScriptContent","templated":true},"m_connector":{"href":"https://{instance_url}/api/integrations/mconnector","title":"Helps third party integrations by providing them useful information"},"massedit_table":{"href":"https://{instance_url}/api/massedit/table","title":"Execute mass edit on a selection"},"massedit_updatetable":{"href":"https://{instance_url}/api/massedit/updatetable","title":"Save mass edit changes on a selection"},"massedits":{"href":"https://{instance_url}/api/massedits{?skip,take}","title":"Your mass edit jobs.","templated":true},"member_security":{"href":"https://{instance_url}/api/membersecurity/{definition}/members/{member}","title":"Gets the users and usergroups for who member-security is defined for a given member.","templated":true},"membergroup_security":{"href":"https://{instance_url}/api/membersecurity/{definition}/membergroups/{membergroup}","title":"Gets the users and usergroups for who member-security is defined for a given membergroup.","templated":true},"menu_by_id":{"href":"https://{instance_url}/api/menu/{id}?culture={culture}","title":"Get the menu with the specified id.","templated":true},"mgmt_page_by_id":{"href":"https://{instance_url}/api/portalpagesmgmt/{id}/{culture}","title":"Get the page with the specified id.","templated":true},"notifications":{"href":"https://{instance_url}/api/notifications{?global}","title":"Your notifications","templated":true},"onedrive_authenticate":{"href":"https://{instance_url}/api/onedrive/authenticate","title":"Authenticate with onedrive"},"onedrive_connect":{"href":"https://{instance_url}/api/onedrive/connect","title":"Connect to onedrive"},"onedrive_disconnect":{"href":"https://{instance_url}/api/onedrive/disconnect","title":"Disconnect from onedrive"},"order_profile_for_entity":{"href":"https://{instance_url}/api/orderprofiles/{id}","title":"Gets the order profile for the entity with specified id.","templated":true},"package":{"href":"https://{instance_url}/api/package","title":"Package import/export links"},"page_by_id":{"href":"https://{instance_url}/api/pages/{id}/{culture}","title":"Get the page with the specified id.","templated":true},"pages":{"href":null,"title":"Your pages"},"permissions_for_entity":{"href":"https://{instance_url}/api/entities/{id}/permissions","title":"Your permissions for the specified entity","templated":true},"policy_by_id":{"href":"https://{instance_url}/api/policies/{id}","title":"Policy resource for given user of group id.","templated":true},"privileges":{"href":"https://{instance_url}/api/privileges/{id}","title":"Privileges for usergroup","templated":true},"project":{"href":"https://{instance_url}/api/project/{name}{?entityids,noParents,culture}","title":"Get a project resource by name","templated":true},"publication_metadata_by_id":{"href":"https://{instance_url}/api/print/publication/metadata/{id}?culture={culture}&quality={quality}","title":"Fetch the metadata of a publication's PDF file with the specified id, culture and quality","templated":true},"publish_script_content":{"href":"https://{instance_url}/api/scripts/{scriptContentId}/publish","title":"Publishes a draft script content.","templated":true},"related_paths_by_definition":{"href":"https://{instance_url}/api/entitydefinitions/{name}/relatedpaths{?name}","title":"Get the related paths for the specified definition name","templated":true},"remove_search_filters":{"href":"https://{instance_url}/api/search/remove","title":"Remove one or more search filters from a query."},"renditions":{"href":"https://{instance_url}/api/renditions","title":"To get information about a rendition for an entity."},"reports":{"href":"https://{instance_url}/api/reports/{action}{?skip,take}","title":"Actions on ReportingController","templated":true},"request_draft_script_content":{"href":"https://{instance_url}/api/scripts/{scriptId}/draft","title":"Requests a draft script content for script.","templated":true},"reset_password":{"href":"https://{instance_url}/api/account/{userId}/resetpassword","title":"Resets the password of the specified user.","templated":true},"resource":{"href":"https://{instance_url}/api/resource{?key,culture}","title":"Your translations","templated":true},"roles":{"href":"https://{instance_url}/api/roles","title":"Provides functionality to get the roles for users and groups.","templated":true},"roles_for_entity":{"href":"https://{instance_url}/api/entities/{id}/roles","title":"Get the roles for the specified entity","templated":true},"savedselections":{"href":"https://{instance_url}/api/savedselections{?searchIdentifier,savedSelectionType,fullText,skip,take,sort,order,sortCulture}","title":"Your saved selections.","templated":true},"search":{"href":"https://{instance_url}/api/search","title":"Search"},"selection":{"href":"https://{instance_url}/api/selection/{selectionPool}/{definitionName}","title":"Get, edit or delete your selection","templated":true},"send_confirmation_email":{"href":"https://{instance_url}/api/account/{userId}/sendconfirmationemail","title":"Sends confirmation email to the specified user.","templated":true},"send_notification":{"href":"https://{instance_url}/api/notifications/{type}","title":"Sends out a notification.","templated":true},"set_user_password":{"href":"https://{instance_url}/api/account/{userId}/setpassword","title":"Set the password of the user with the given id.","templated":true},"setting_by_name":{"href":"https://{instance_url}/api/settings/{category}/{name}","title":"Get the setting for specified category and name.","templated":true},"settings":{"href":"https://{instance_url}/api/settings{?skip,take}","title":"Your settings"},"settings_by_category":{"href":"https://{instance_url}/api/settings/{category}{?skip,take}","title":"Get the settings for specified category.","templated":true},"speedtest":{"href":"https://{instance_url}/api/status/speedtest/{action}","title":"Speedtest by action","templated":true},"status":{"href":"https://{instance_url}/api/status","title":"M Status information"},"suggestion":{"href":"https://{instance_url}/api/suggest","title":"suggestion"},"taxonomy":{"href":"https://{instance_url}/api/taxonomy{?skip,take,fullText,excludeSystemOwnedDefinitions}","title":"Your taxonomy definitions","templated":true},"user_by_id":{"href":"https://{instance_url}/api/users/{id}{?culture}","title":"User with the given id.","templated":true},"usergroup_by_id":{"href":"https://{instance_url}/api/usergroups/{id}{?culture}","title":"User group with the givenn id.","templated":true},"usergroups":{"href":"https://{instance_url}/api/usergroups{?skip,take,culture}","title":"Your user groups.","templated":true},"userProfile":{"href":"https://{instance_url}/api/userProfile{?key}","title":"Your user profile"},"users":{"href":"https://{instance_url}/api/users{?skip,take,culture}","title":"Your users.","templated":true}}}

Request 3: getting the entity

19/12/2018 13:34:04 | Debug | Http request:
        Method: POST
        Uri: https://{instance_url}/api/entities/query
        Headers:
                Accept: application/json
                Authorization: Bearer 3iWzO6LgQ9g72wvOs4BO7qtAGx7zkBgtmTlvAoL4a7TXMdUKaej13QOqTy_qRBZqACaKFoWBNwCXYL4JKDNor18GGeQfdQ_vk1yk7iHwGVRCgIvfJ2YqhnKAPek3QD6qbG4oRhpsrZUkyZUB6RAcKFZ93xaExWYd_JJ5vGtQCF6_LoyXyP5TG6O0JToITpzLAclYyUDZ2-HZKIZFITsc5lXj38KsDWrVcpZVCyjh86l4KoTYGtRbZmZryMX9TPhT

        Content: {"filter":{"type":"Id","operator":"Equals","value":9071,"values":null},"skip":null,"take":50,"sorting":null,"scroll_time":null,"entity_load_options":null,"load_configuration":{"load_entities":true,"culture_option":{"load_option":"Default"},"property_option":{"load_option":"All"},"relation_option":{"load_option":"None"}}}

Response 3: getting the entity

19/12/2018 13:34:04 | Debug | Http response:
        Status: OK (200)
        Headers:
                Cache-Control: no-store
                Server:
                X-Frame-Options: DENY
                X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcU3R5bGVMYWJzXHN0eWxlbGFicy5tXHNyY1xTdHlsZWxhYnMuTS5Qb3J0YWwuV2ViLlVJXGFwaVxlbnRpdGllc1xxdWVyeQ==?=
                X-Content-Type-Options: nosniff
                Date: Wed, 19 Dec 2018 12:34:04 GMT

        Content: {"items":[{"link":{"href":"https://{instance_url}/api/entities/9071"},"entity":{"id":9071,"identifier":"T_backTitleOnly.title","cultures":["en-US"],"properties":{"TranslationName":"T_backTitleOnly.title","OriginalValue":{"en-US":"Back"},"Value":{}},"relations":{},"created_by":{"href":"https://{instance_url}/api/entities/6","title":"The user who created the entity"},"created_on":"2018-12-19T12:09:31.1825396Z","modified_by":{"href":"https://{instance_url}/api/entities/6","title":"The user who last modified the entity"},"modified_on":"2018-12-19T12:09:31.1825396Z","entitydefinition":{"href":"https://{instance_url}/api/entitydefinitions/Portal.Translation","title":"The entity definition for this entity"},"copy":{"href":"https://{instance_url}/api/entities/9071/copy","title":"Copy this entity"},"permissions":{"href":"https://{instance_url}/api/entities/9071/permissions","title":"The permissions on this entity"},"lifecycle":{"href":"https://{instance_url}/api/entities/9071/lifecycle","title":"The lifecycle action for this entity."},"saved_selections":{"href":"https://{instance_url}/api/entities/9071/savedselections","title":"The saved selections this entity belongs to"},"annotations":{"href":"https://{instance_url}/api/entities/9071/annotations","title":"Annotations for this entity"},"is_root_taxonomy_item":false,"is_path_root":false,"inherits_security":true,"is_system_owned":false,"version":1}}],"total_items":1,"returned_items":1,"minimal_schema_list":[{"definition_name":"Portal.Translation","properties":[{"name":"TranslationName","type":"String"},{"name":"OriginalValue","multilingual":true,"type":"String"},{"name":"Value","multilingual":true,"type":"String"}],"relations":[]}]}

See also

Can we improve this article ? Provide feedback