Skip to content
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

Use MSBuild Logging APIs for Task output instead of StdOut #933

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
respond to some logging feedback
  • Loading branch information
baronfel committed Mar 1, 2025
commit 5ccacf951fcaccf51f61116ed47636ed71fd0e49
20 changes: 15 additions & 5 deletions src/Microsoft.Sbom.Targets/GenerateSbomTask.cs
Original file line number Diff line number Diff line change
@@ -39,16 +39,14 @@ public override bool Execute()
{
try
{
var taskLoggingHelper = new TaskLoggingHelper(this);

// Validate required args and args that take paths as input.
if (!ValidateAndSanitizeRequiredParams() || !ValidateAndSanitizeNamespaceUriUniquePart())
{
return false;
}

var logVerbosity = ValidateAndAssignVerbosity();
var msbuildLogger = new MSBuildLogger(taskLoggingHelper);
var msbuildLogger = new MSBuildLogger(this.Log);
Serilog.Log.Logger = msbuildLogger;
var taskHost = Host.CreateDefaultBuilder()
.ConfigureServices((host, services) =>
@@ -115,15 +113,27 @@ public override bool Execute()

foreach (var error in result.Errors)
{
Log.LogMessage(MessageImportance.Normal, "{0}({1}) - {2} - {3}", error.Entity.Id, error.Entity.EntityType, error.ErrorType, error.Details);
var file = error.Entity is FileEntity fe ? fe.Path : null;
Log.LogMessage(
subcategory: null,
code: null,
helpKeyword: null,
file: file,
lineNumber: 0,
columnNumber: 0,
endLineNumber: 0,
endColumnNumber: 0,
importance: MessageImportance.Normal,
message: "{0}({1}) - {2} - {3}",
messageArgs: [error.Entity.Id, error.Entity.EntityType, error.ErrorType, error.Details]);
}

return result.IsSuccessful;
}
catch (Exception e)
{
Log.LogError($"SBOM generation failed: {e.Message}");
return Log.HasLoggedErrors;
return !Log.HasLoggedErrors;
}
}