Logging a Unified Service Desk Hosted Control with TraceLogger

Leave a comment

Unified Service Desk comes with different kinds of logging. You can see this logging in the UnifiedServiceDesk.exe.config file under switches:

You can also implement logging in your custom hosted controls. Here we will go through how to set this up.

First, create a new custom hosted control:

Open the USDControl.xaml.cs. You will see a template for adding custom logging. We will add some test lines of code to write to the trace log. Note when initializing the TraceLogger, we use the traceSourceName to define the name of the trace. We will use “MyTraceSource”:

MyLogWriter = new TraceLogger(traceSourceName:"MyTraceSource");
MyLogWriter.Log("This is a test writing to the log file as MyTraceSouce");

You can change the reporting level in the code – default is Information:

Note the comments that appear in the USD code. We will use this in our config file shortly:

// This will create a log writer with the same name as your hosted control. 
// LogWriter = new TraceLogger(traceSourceName:"MyTraceSource");
 
// If you utilize this feature,  you would need to add a section to the system.diagnostics settings area of the UnifiedServiceDesk.exe.config
//<source name="MyTraceSource" switchName="MyTraceSwitchName" switchType="System.Diagnostics.SourceSwitch">
//    <listeners>
//        <add name="console" type="System.Diagnostics.DefaultTraceListener"/>
//        <add name="fileListener"/>
//        <add name="USDDebugListener" />
//        <remove name="Default"/>
//    </listeners>
//</source>
 
// and then in the switches area : 
//<add name="MyTraceSwitchName" value="Verbose"/>

Next, compile the USD control and copy it to the USD directory.

We will now need to update the UnifiedServiceDesk.exe.config file. Add the lines for the source in the sources section:

Then add a line for the switches that defines what level of logging to log:

  • All
  • Verbose
  • Error
  • Warning
  • Information

Start USD and open the new custom hosted control. We will do this by running the default action:

This will now write to the USD log files. These are located in %appdata%\Roaming\Microsoft\Microsoft Dynamics® 365 Unified Service Desk\USDVersion. The file should look something like below:

On opening the file you should see something like below:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *