Skip to content

Bugfix/logging #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions src/GitVersionTask/BuildLogger.cs

This file was deleted.

12 changes: 2 additions & 10 deletions src/GitVersionTask/GenerateGitVersionInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ namespace GitVersionTask

public class GenerateGitVersionInformation : GitVersionTaskBase
{
TaskLogger logger;

public GenerateGitVersionInformation()
{
logger = new TaskLogger(this);
Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}

[Required]
Expand Down Expand Up @@ -42,18 +38,14 @@ public override bool Execute()
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
this.LogError("Error occurred: " + exception);
return false;
}
finally
{
Logger.Reset();
}
}

void InnerExecute()
Expand Down
12 changes: 2 additions & 10 deletions src/GitVersionTask/GetVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ namespace GitVersionTask

public class GetVersion : GitVersionTaskBase
{
TaskLogger logger;

public GetVersion()
{
logger = new TaskLogger(this);
Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}

[Required]
Expand Down Expand Up @@ -128,18 +124,14 @@ public override bool Execute()
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
this.LogError("Error occurred: " + exception);
return false;
}
finally
{
Logger.Reset();
}
}
}
}
22 changes: 22 additions & 0 deletions src/GitVersionTask/GitVersionTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using GitVersion;
using GitVersion.Helpers;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

public abstract class GitVersionTaskBase : Task
Expand All @@ -13,11 +14,32 @@ protected GitVersionTaskBase()
{
var fileSystem = new FileSystem();
executeCore = new ExecuteCore(fileSystem);
GitVersion.Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}

protected ExecuteCore ExecuteCore
{
get { return executeCore; }
}

public void LogDebug(string message)
{
this.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Low));
}

public void LogWarning(string message)
{
this.BuildEngine.LogWarningEvent(new BuildWarningEventArgs(string.Empty, string.Empty, null, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
}

public void LogInfo(string message)
{
this.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, string.Empty, "GitVersionTask", MessageImportance.Normal));
}

public void LogError(string message, string file = null)
{
this.BuildEngine.LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, file, 0, 0, 0, 0, message, string.Empty, "GitVersionTask"));
}
}
}
26 changes: 0 additions & 26 deletions src/GitVersionTask/TaskLogger.cs

This file was deleted.

12 changes: 2 additions & 10 deletions src/GitVersionTask/UpdateAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ namespace GitVersionTask

public class UpdateAssemblyInfo : GitVersionTaskBase
{
TaskLogger logger;

public UpdateAssemblyInfo()
{
logger = new TaskLogger(this);
Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}

[Required]
Expand Down Expand Up @@ -46,18 +42,14 @@ public override bool Execute()
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
this.LogError("Error occurred: " + exception);
return false;
}
finally
{
Logger.Reset();
}
}

void InnerExecute()
Expand Down
20 changes: 6 additions & 14 deletions src/GitVersionTask/WriteVersionInfoToBuildLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ namespace GitVersionTask

public class WriteVersionInfoToBuildLog : GitVersionTaskBase
{
readonly TaskLogger logger;

public WriteVersionInfoToBuildLog()
{
logger = new TaskLogger(this);
Logger.SetLoggers(this.LogDebug, this.LogInfo, this.LogWarning, s => this.LogError(s));
}

[Required]
Expand All @@ -29,18 +25,14 @@ public override bool Execute()
}
catch (WarningException errorException)
{
logger.LogWarning(errorException.Message);
this.LogWarning(errorException.Message);
return true;
}
catch (Exception exception)
{
logger.LogError("Error occurred: " + exception);
this.LogError("Error occurred: " + exception);
return false;
}
finally
{
Logger.Reset();
}
}

void InnerExecute()
Expand All @@ -58,12 +50,12 @@ void WriteIntegrationParameters(IEnumerable<IBuildServer> applicableBuildServers
{
foreach (var buildServer in applicableBuildServers)
{
logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
logger.LogInfo(buildServer.GenerateSetVersionMessage(variables));
logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
this.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
this.LogInfo(buildServer.GenerateSetVersionMessage(variables));
this.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, variables))
{
logger.LogInfo(buildParameter);
this.LogInfo(buildParameter);
}
}
}
Expand Down