Skip to content

Logging

With the introduction of the ILogger interface in Dataverse plugins, developers now have multiple logging targets available—namely, traditional plugin trace logs and Application Insights. While this adds flexibility, it also introduces the potential for inconsistency in how logs are written and managed.

To address this, the ILoggingService was introduced as a unified logging abstraction that standardizes logging across both trace logs and Application Insights. It provides a centralized, consistent way to write logs, and includes a variety of extension methods to simplify common scenarios.

The ILoggingService also supports log levels through a LogLevel enum, allowing you to categorize log output by severity (e.g., Debug, Info, Warning, Error). A key feature is that logs written at the Debug level are only emitted when the plugin assembly is built in the Debug configuration. In Release builds, these logs are automatically suppressed, helping to reduce noise and overhead in production environments.

Examples

Example plugin using ILoggingService
namespace Imprevis.Dataverse.Plugins.Test
{
    using Imprevis.Dataverse.Plugins;
    using Imprevis.Dataverse.Plugins.Extensions;
    using Microsoft.Xrm.Sdk;

    public class TestPlugin : Plugin<TestPluginRunner> { }

    public class TestPluginRunner : IPluginRunner
    {
        public TestPluginRunner(IPluginExecutionContext context, ILoggingService logger)
        {
            Context = context;
            Logger = logger;
        }

        public IPluginExecutionContext Context { get; }
        public ILoggingService Logger { get; }

        public void Execute()
        {
            Logger.LogLevel = LogLevel.Debug;

            var target = Context.GetTarget();

            Logger.LogDebug(target);
        }
    }
}

When this plugin execute, it will output something similar to this in the logs:

Example trace log output
[12:00:00.000] Entity = account : 00000000-0000-0000-0000-000000000000
[12:00:00.000] Attributes
 - accountid = 00000000-0000-0000-0000-000000000000
 - name = Account Name
 - primarycontactid = contact : 00000000-0000-0000-0000-000000000000