diff --git a/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/AzureDevOpsTraceLoggerAdapter.cs b/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/AzureDevOpsTraceLoggerAdapter.cs index 53b0797..097d655 100644 --- a/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/AzureDevOpsTraceLoggerAdapter.cs +++ b/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/AzureDevOpsTraceLoggerAdapter.cs @@ -1,5 +1,6 @@ namespace Capgemini.PowerApps.PackageDeployerTemplate.Adapters { + using System; using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; using Microsoft.Xrm.Tooling.PackageDeployment.CrmPackageExtentionBase; @@ -20,17 +21,25 @@ public AzureDevOpsTraceLoggerAdapter(TraceLogger traceLogger) } /// - protected override string GetPrefix(LogLevel logLevel) + public override void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { + base.Log(logLevel, eventId, state, exception, formatter); + + if (!this.IsEnabled(logLevel)) + { + return; + } + + var message = formatter(state, exception); switch (logLevel) { case LogLevel.Warning: - return "##[task.logissue type=warning]"; + Console.Write($"##[task.logissue type=warning]{message}"); + break; case LogLevel.Error: case LogLevel.Critical: - return "##[task.logissue type=error]"; - default: - return string.Empty; + Console.WriteLine($"##[task.logissue type=error]{message}"); + break; } } } diff --git a/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/TraceLoggerAdapter.cs b/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/TraceLoggerAdapter.cs index 72fbf3e..73db4eb 100644 --- a/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/TraceLoggerAdapter.cs +++ b/src/Capgemini.PowerApps.PackageDeployerTemplate/Adapters/TraceLoggerAdapter.cs @@ -56,7 +56,7 @@ public TraceLoggerAdapter(TraceLogger traceLogger) public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None; /// - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { if (!this.IsEnabled(logLevel)) { @@ -74,18 +74,8 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except } this.traceLogger.Log( - $"{this.GetPrefix(logLevel)}{message} {(exception != null ? exception.StackTrace : string.Empty)}", + $"{message} {(exception != null ? exception.StackTrace : string.Empty)}", LogLevelMap[logLevel]); } - - /// - /// Gets the prefix for a given log level. - /// - /// The log level. - /// The prefix. - protected virtual string GetPrefix(LogLevel logLevel) - { - return string.Empty; - } } } \ No newline at end of file