Configure enhanced diagnostic logging for custom hosted controls


Unified Service Desk enables you to configure diagnostic logging to record operational events and errors in the client application to a log file, which can be later used to identify and troubleshoot performance issues or errors. For more information about diagnostic logging, see TechNet: Configure client diagnostic logging in Unified Service Desk.

With Unified Service Desk 2.2.1 release, diagnostic logging for predefined hosted control types has been enhanced to provide rich information about an exception or error, such as the source where the error occurred (hosted control name, hosted control type, session ID) and detailed information about the error along with the stack trace. The rich diagnostic information greatly improves in quickly identifying and troubleshooting issues in Unified Service Desk.

You can leverage the same enhanced diagnostic logging capabilities available in the predefined hosted controls for your custom controls by using LogException Method in your custom control code to provide rich information about the exception (if it occurs) so that its easier to identify if the issue is caused by your custom code or some other control in Unified Service Desk.

LogException Method is overloaded, and internally uses DynamicsLogger to provide rich diagnostic information for exceptions in your custom control. Use one of the following two signatures to use this method:

  • Pass in the exception object and the event type that caused the trace (optional). If you do not specify the event type, by default Error trace event type is passed:

    LogException(Exception ex, TraceEventType eventType = TraceEventType.Error);
  • Pass in the string value for custom error message, event type that caused the trace, and the exception object:

    LogException(string errorMessage, TraceEventType eventType, Exception ex);

Here is an example of the diagnostic information as a result of using LogException Method where detailed information about the source (session ID, hosted control name and type) and the exception detail is logged:

Exception raised in :  Session ID : d14893b0-6859-4827-9ddc-949d3fd36854 - Application : DemoControl - USD Component Type : USDHostedControl - Hosting Type : USD Hosted Control - Display Group : MainPanel - 
Exception details: 
Source: DemoControl
Target: Void ThrowAndLogException_Click(System.Object, System.Windows.RoutedEventArgs)
Exception: SampleLogException
StackTrace:   at DemoControl.USDControl.ThrowAndLogException_Click(Object sender, RoutedEventArgs e

See Also

TechNet: Configure client diagnostic logging in Unified Service Desk
Unified Service Desk Hosted Controls
Walkthrough: Create custom hosted control for Unified Service Desk

Unified Service Desk 2.0

© 2017 Microsoft. All rights reserved. Copyright