DEVKIT1012 - phuocle/Dynamics-Crm-DevKit GitHub Wiki
This analyzer recommends using ITracingService in plug-in classes. Tracing is essential for debugging and monitoring plugin execution in Dynamics 365 / Dataverse.
📚 Use ITracingService in Plug-ins
Use ITracingService in plug-ins to write diagnostic information that helps debug and monitor your plug-ins.
Without tracing:
- Difficult Debugging: Production issues are hard to diagnose
- No Execution Visibility: Can't see what your plugin is doing
- Slow Incident Resolution: Takes longer to identify root cause
- Missing Audit Trail: No record of plugin behavior
The analyzer reports when:
- A class implements
IPlugininterface - The class doesn't contain any reference to
ITracingService
public class AccountPlugin : IPlugin
{
// ⚠️ No tracing - difficult to debug
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider
.GetService(typeof(IPluginExecutionContext));
var target = (Entity)context.InputParameters["Target"];
// Do something with target...
}
}public class AccountPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// ✅ Get tracing service for debugging
var tracingService = (ITracingService)serviceProvider
.GetService(typeof(ITracingService));
tracingService.Trace("AccountPlugin: Execute started");
var context = (IPluginExecutionContext)serviceProvider
.GetService(typeof(IPluginExecutionContext));
tracingService.Trace("Message: {0}, Stage: {1}",
context.MessageName, context.Stage);
var target = (Entity)context.InputParameters["Target"];
tracingService.Trace("Target entity: {0}, Id: {1}",
target.LogicalName, target.Id);
// Do something with target...
tracingService.Trace("AccountPlugin: Execute completed");
}
}- Get ITracingService: Retrieve from the service provider
- Add Trace Calls: Log entry/exit, key variables, and decisions
- Include Context: Log message name, stage, entity details
public void Execute(IServiceProvider serviceProvider)
{
+ var tracingService = (ITracingService)serviceProvider
+ .GetService(typeof(ITracingService));
+ tracingService.Trace("Plugin started");
+
var context = (IPluginExecutionContext)serviceProvider
.GetService(typeof(IPluginExecutionContext));
+
+ tracingService.Trace("Depth: {0}", context.Depth);
// ... rest of code
+
+ tracingService.Trace("Plugin completed");
}To view trace logs in Dynamics 365:
- Go to Settings → Plug-in Trace Log
- Filter by plugin assembly or message
- Review the
MessageBlockfield for trace output
Note: Tracing must be enabled in the environment (Plug-in Trace Log Setting).
If you intentionally don't want tracing (e.g., a minimal helper plugin):
#pragma warning disable DEVKIT1012
public class MinimalPlugin : IPlugin
{
// No tracing needed
}
#pragma warning restore DEVKIT1012Or in .editorconfig:
[*.cs]
dotnet_diagnostic.DEVKIT1012.severity = none| Property | Value |
|---|---|
| Rule ID | DEVKIT1012 |
| Category | DynamicsCrm.DevKit |
| Severity | Warning |
| Enabled by default | Yes |