Sometime we want to know what is going on in our plugin code. When the plugin code is very large then we need to write the code for every step which is executed successfully or not.
For Debugging a Plugin we can –
- Use ITracingService
- Attach Plugin Registration Tool with VS and debug it.
For more info please refer the below links.
To review more options for external logging, you can also go through the below link.
Author by Salim Adamon
In this Blog, we’ll talk about creating log in plug-in using custom entity.
Let’s create an entity i.e. am_log in our CRM.
and create attributes which are required for this entity like
am_status , am_errordescription.
As we all know that creating a record in CRM is very easy but If you are writing logs in a failing transaction of Plugin, then the entire transaction will be rolled back including creation of logging records.
To avoid this roll back of logging records we can use ExecuteMultipleRequest.
For more info about ExecuteMultipleRequest refer to below link
In this process first we create a plugin, here named as LoggingUsingCustomEntity.
First we need to Create object for ExcuteMultipleRequest and assign settings that define execution behavior i.e.
Lets say before creating a new account we need to count all Accounts(or any other business requirement) that already present in CRM that create success log in our Log Entity.
Now we write invalid expression for creating new account that generate error log in our Log entity.
According above code log records will create two times, one for getting all accounts successfully and other for error that is Account doesn’t contain “Name” attribute.
Let’s we deployed this plugin code on Account Create Message and see what will be generates in Log entity.
It created successfully what we expected 🙂
It won’t be created and also roll backed if we use normal create request here.
here is the link of Plugin complete code.
Thanks for visiting my blog.
Do some creative stuff in CRM !!! 🙂