{"id":1233,"date":"2015-04-24T16:48:35","date_gmt":"2015-04-24T11:18:35","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=1233"},"modified":"2015-04-24T16:48:35","modified_gmt":"2015-04-24T11:18:35","slug":"plug-in-trace-log-in-crm-2015-update-1","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2015\/04\/plug-in-trace-log-in-crm-2015-update-1\/","title":{"rendered":"Plug-in Tracing in Dynamics CRM 2015 Update 1"},"content":{"rendered":"<p>Before CRM 2015\u00a0SP1 update, an alternative option to debug the Plug-in or Workflow for developers was to use tracing messages which would help to trace the program using custom messages.<\/p>\n<p>The developer had to manually throw an exception in order to trace the program. And then when the plug in\/workflow is triggered a dialog is shown up to \u201cDownload the Log File\u201d which contains the tracing information.<\/p>\n<p>So, the user\/Developer had to read the tracing from the downloaded text file, which was a tedious job itself.<\/p>\n<p>So now in CRM 2015 SP1 update, we have one more option in which we have a new Entity called \u201cPlug-in Trace Logs\u201d which itself creates record for any exception occurred or thrown by the developer.<\/p>\n<p>But in order to enable this feature we need to make following settings in CRM.<\/p>\n<ul>\n<li>Go to Settings &gt;&gt; Administration<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/11.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1247\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/11.png\" alt=\"1\" width=\"616\" height=\"325\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Under Administration\u00a0 &gt;&gt; System Settings\u00a0 &gt;&gt; Customization Tab<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/22.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1246\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/22.png\" alt=\"2\" width=\"560\" height=\"326\" \/><\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>So as we can see here there is an option \u201cEnable logging to plug-in trace log\u201d. By default it is Off, we need to select the option \u201cException\u201d in order to enable the creation of Plug-in trace log records in case any exception or error occurs.<\/p>\n<p>There\u2019s one more option in addition to this as mentioned in SDK and i.e. \u201cAll\u201d. In the preview Version we don\u2019t have it.<\/p>\n<p>It\u2019s mentioned that if we select \u201cAll\u201d then the tracing information would be written to Trace Log record upon complete code execution or any error occurred throw custom code.<\/p>\n<p>Once we have enabled the feature, we can view the Trace Log Records under:<\/p>\n<p>Settings &gt;&gt; Plug In Trace Log Entity:<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/31.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1248\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/31.png\" alt=\"3\" width=\"605\" height=\"252\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Records are created in CRM as below, which are read only just like System Job records to find out the error occurred.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/42.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1252\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/42.png\" alt=\"4\" width=\"548\" height=\"306\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now let\u2019s see what this record actually contains and why it simplifies the earlier process of debugging Plug-In and workflow using ITracingService interface.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/5.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1238\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/5.png\" alt=\"5\" width=\"874\" height=\"484\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>You can see the record contains attributes like Message Name, Primary Entity, Mode etc which helps to get the information related to Plug-in.<\/p>\n<p>As shown below it contains two fields Message Block and Exception Details which contains the actual data the user \/ developer is keen to understand.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/6.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1239\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/6.png\" alt=\"6\" width=\"960\" height=\"535\" \/><\/a><\/p>\n<p><strong>Message Block<\/strong>: Contains the actual Tracing information which we specify in our Plug-in \/Custom Workflow to Trace method. For e.g. tracing.Trace(\u201cWorkflow Started\u201d); where tracing is an object of ITracingService.<\/p>\n<p><strong>Exception Details<\/strong>: Contains the Exception related information which has occurred in Plug-in or Custom Workflow.<\/p>\n<p>Also we can view the Trace Log records using Advanced Find. Hence we can even filter out records based on the Query specified in Advance find. Below is an example of that:<\/p>\n<p>We are selecting only those records which are created due\u00a0to Plug-ins.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/72.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1255\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/72.png\" alt=\"7\" width=\"576\" height=\"289\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In addition to this there\u2019s one more advantage of the Trace Log Entity.<\/p>\n<p>Before, this feature was introduced the developers used to create a Custom Entity for storing Log Records so that they could trace the tracing information or exception details. But it was quite tricky in case of Transactional Plug-ins, as we know if any part of code fails in it, the entire changes would roll back and the custom entity to store the tracing information is not\u00a0 created. Although now, with this System Trace Log Entity the Trace records will be created even if \u00a0the code fails.<\/p>\n<p>Let\u2019s take an example to understand it. We have registered a Plug-in on \u201cQualify Lead\u201d on the Post Operation.<\/p>\n<p>Let\u2019s qualify the lead and suppose an exception occurs during execution as below:<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/8.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1241\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/8.png\" alt=\"8\" width=\"954\" height=\"372\" \/><\/a><\/p>\n<p>We can \u201cDownload Log File\u201d and read the \u201cTracing Information\u201d which we used to do earlier. Or now we have an option to read the related Trace Log Record which is created even if the changes are Roll Back in the system\u00a0 i.e. Lead\u00a0 is not qualified.<\/p>\n<p>The related trace log record created in the system is as below:<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/9.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1242\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/04\/9.png\" alt=\"9\" width=\"829\" height=\"534\" \/><\/a><\/p>\n<p>Thus, as we can see now the trace log record is created anyhow in the system even if the operations in the Plug-in are roll backed.<\/p>\n<p>Now, who can view these records by default in CRM?<\/p>\n<p>By default, the System Administrators and System Customizers can view these records but the access to view can be granted to other Users too.<\/p>\n<p><strong>NOTE<\/strong>: Trace logs will only be written to the trace log entities if the plug-in developer uses tracing within the plug-in.<\/p>\n<p>If we have enabled this feature in our System, then Trace Log records will henceforth be created in CRM for the entities having Plug-in or Custom Workflow (which implements ITracingService) registered on it. Due to this more number of Trace log records could be created in CRM, so in order to manage this we can create a Bulk Deletion Job which we can schedule such that the trace log records would be deleted over fixed interval of time.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before CRM 2015\u00a0SP1 update, an alternative option to debug the Plug-in or Workflow for developers was to use tracing messages which would help to trace the program using custom messages. The developer had to manually throw an exception in order to trace the program. And then when the plug in\/workflow is triggered a dialog is\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2015\/04\/plug-in-trace-log-in-crm-2015-update-1\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15,23,24,42],"tags":[398,597,1330,1841],"class_list":["post-1233","post","type-post","status-publish","format-standard","hentry","category-development","category-dynamics-crm-2015-update-1","category-dynamics-crm-2016","category-plugin","tag-crm-2015","tag-dynamics-crm-2015","tag-plugins","tag-workflow"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/1233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=1233"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/1233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=1233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=1233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=1233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}