Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Fix MSBuild task logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Oct 8, 2016
1 parent 73cb03b commit b5a1619
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/GitLinkTask/GitLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
namespace GitLinkTask
{
using System;
using System.IO;
using System.Linq;
using global::GitLink;
using global::GitLink.Pdb;
using global::GitLink.Providers;
using Catel.Logging;
using global::GitLink;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand All @@ -30,7 +26,7 @@ public class GitLink : Task

public override bool Execute()
{
LogManager.GetCurrentClassLogger().LogMessage += this.LinkProject_LogMessage;
LogManager.AddListener(new MSBuildListener(this.Log));

var options = new LinkOptions
{
Expand All @@ -43,25 +39,35 @@ public override bool Execute()
return success && !this.Log.HasLoggedErrors;
}

private void LinkProject_LogMessage(object sender, LogMessageEventArgs e)
private class MSBuildListener : LogListenerBase
{
switch (e.LogEvent)
private readonly TaskLoggingHelper log;

internal MSBuildListener(TaskLoggingHelper log)
{
this.log = log;
}

protected override void Write(ILog log, string message, LogEvent logEvent, object extraData, LogData logData, DateTime time)
{
case LogEvent.Error:
this.Log.LogError(e.Message);
break;
case LogEvent.Warning:
this.Log.LogWarning(e.Message);
break;
case LogEvent.Info:
this.Log.LogMessage(MessageImportance.Normal, e.Message);
break;
case LogEvent.Debug:
this.Log.LogMessage(MessageImportance.Low, e.Message);
break;
default:
break;
switch (logEvent)
{
case LogEvent.Error:
this.log.LogError(message);
break;
case LogEvent.Warning:
this.log.LogWarning(message);
break;
case LogEvent.Info:
this.log.LogMessage(MessageImportance.Normal, message);
break;
case LogEvent.Debug:
this.log.LogMessage(MessageImportance.Low, message);
break;
default:
break;
}
}
}
}
}
}

0 comments on commit b5a1619

Please sign in to comment.