namespace <%= client %>.<%= package %>.BusinessLogic.Logging { using System; using System.Globalization; using Microsoft.Xrm.Sdk; /// /// Logs messages using the tracing service. /// public class TracingServiceLogWriter : ILogWriter { private readonly ITracingService tracingService; private readonly bool addTimestamps; /// /// Initializes a new instance of the class. /// /// The tracing service. /// Whether or not to timestamp messages. public TracingServiceLogWriter(ITracingService tracingService, bool timestamp = false) { this.tracingService = tracingService ?? throw new ArgumentNullException(nameof(tracingService)); this.addTimestamps = timestamp; } /// public void Log(Severity severity, string tag, string message) { this.tracingService.Trace(this.FormatMessage(severity, tag, message)); } private string FormatMessage(Severity severity, string tag, string message) { return $"{(this.addTimestamps ? $"{DateTime.UtcNow.ToString("o", CultureInfo.CurrentCulture)}: " : string.Empty)}{tag}: {severity}: {message}"; } } }