Skip to content

Commit

Permalink
fix: individual issues not logged on Azure DevOps (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewingjm authored Mar 17, 2021
1 parent ed6a118 commit b15dcbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,17 +21,25 @@ public AzureDevOpsTraceLoggerAdapter(TraceLogger traceLogger)
}

/// <inheritdoc/>
protected override string GetPrefix(LogLevel logLevel)
public override void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> 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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public TraceLoggerAdapter(TraceLogger traceLogger)
public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None;

/// <inheritdoc/>
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (!this.IsEnabled(logLevel))
{
Expand All @@ -74,18 +74,8 @@ public void Log<TState>(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]);
}

/// <summary>
/// Gets the prefix for a given log level.
/// </summary>
/// <param name="logLevel">The log level.</param>
/// <returns>The prefix.</returns>
protected virtual string GetPrefix(LogLevel logLevel)
{
return string.Empty;
}
}
}

0 comments on commit b15dcbb

Please sign in to comment.