Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion src/StructuredLogger/BinaryLogger/BinaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ public sealed class BinaryLogger : ILogger
// BuildCheckTracingEvent, BuildCheckAcquisitionEvent, BuildSubmissionStartedEvent
// version 24:
// - new record kind: BuildCanceledEvent
// version 25:
// - add extra information to PropertyInitialValueSetEventArgs and PropertyReassignmentEventArgs and change parsing logic of Message property in them.

// This should be never changed.
// The minimum version of the binary log reader that can read log of above version.
internal const int ForwardCompatibilityMinimalVersion = 18;

// The current version of the binary log representation.
// Changes with each update of the binary log format.
internal const int FileFormatVersion = 24;
internal const int FileFormatVersion = 25;
// The minimum version of the binary log reader that can read log of above version.
// This should be changed only when the binary log format is changed in a way that would prevent it from being
// read by older readers. (changing of the individual BuildEventArgs or adding new is fine - as reader can
Expand Down
49 changes: 37 additions & 12 deletions src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,22 +1358,35 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs()
string location = ReadDeduplicatedString();

string message = fields.Message;
if (_fileFormatVersion >= 13)
if (_fileFormatVersion >= 13 && _fileFormatVersion < 25)
{
message = GetPropertyReassignmentMessage(propertyName, newValue, previousValue, location);
}
else if (_fileFormatVersion >= 25 && !string.IsNullOrEmpty(fields.Message))
{
message = string.Format(fields.Message, propertyName, newValue, previousValue, $"{fields.File} ({fields.LineNumber},{fields.ColumnNumber})");
var extendedEvent = new ExtendedPropertyReassignmentEventArgs(
propertyName,
previousValue,
newValue,
fields.File,
fields.LineNumber,
fields.ColumnNumber,
message);
SetCommonFields(extendedEvent, fields);
return extendedEvent;
}

var e = new PropertyReassignmentEventArgs(
propertyName,
previousValue,
newValue,
location,
message,
fields.HelpKeyword,
fields.SenderName,
fields.Importance);
propertyName,
previousValue,
newValue,
location,
message,
fields.HelpKeyword,
fields.SenderName,
fields.Importance);
SetCommonFields(e, fields);

return e;
}

Expand Down Expand Up @@ -1401,11 +1414,23 @@ private BuildEventArgs ReadPropertyInitialValueSetEventArgs()
string propertyValue = ReadDeduplicatedString();
string propertySource = ReadDeduplicatedString();

var e = new PropertyInitialValueSetEventArgs(
string message = fields.Message;
if (_fileFormatVersion >= 25)
{
string formattedSource = string.IsNullOrEmpty(fields.File)
? propertySource
: $"{fields.File} ({fields.LineNumber},{fields.ColumnNumber})";
message = string.Format(fields.Message, propertyName, propertyValue, formattedSource);
}

var e = new ExtendedPropertyInitialValueSetEventArgs(
propertyName,
propertyValue,
propertySource,
fields.Message,
fields.File,
fields.LineNumber,
fields.ColumnNumber,
message,
fields.HelpKeyword,
fields.SenderName,
fields.Importance);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Build.Framework;

namespace StructuredLogger.BinaryLogger
{
internal class ExtendedPropertyInitialValueSetEventArgs : BuildMessageEventArgs
{
/// <summary>
/// Creates an instance of the <see cref="ExtendedPropertyInitialValueSetEventArgs"/> class.
/// </summary>
/// <param name="propertyName">The name of the property.</param>
/// <param name="propertyValue">The value of the property.</param>
/// <param name="propertySource">The source of the property.</param>
/// <param name="file">The file associated with the event.</param>
/// <param name="line">The line number (0 if not applicable).</param>
/// <param name="column">The column number (0 if not applicable).</param>
/// <param name="message">The message of the property.</param>
/// <param name="helpKeyword">The help keyword.</param>
/// <param name="senderName">The sender name of the event.</param>
/// <param name="importance">The importance of the message.</param>
public ExtendedPropertyInitialValueSetEventArgs(
string propertyName,
string propertyValue,
string propertySource,
string file,
int line,
int column,
string message,
string helpKeyword = null,
string senderName = null,
MessageImportance importance = MessageImportance.Low)
: base(subcategory: null, code: null, file: file, lineNumber: line, columnNumber: column, 0, 0, message, helpKeyword, senderName, importance)
{
PropertyName = propertyName;
PropertyValue = propertyValue;
PropertySource = propertySource;
}

/// <summary>
/// The name of the property.
/// </summary>
public string PropertyName { get; set; }

/// <summary>
/// The value of the property.
/// </summary>
public string PropertyValue { get; set; }

/// <summary>
/// The source of the property.
/// </summary>
public string PropertySource { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Build.Framework;

namespace StructuredLogger.BinaryLogger
{
internal class ExtendedPropertyReassignmentEventArgs : BuildMessageEventArgs
{
/// <summary>
/// Creates an instance of the <see cref="PropertyReassignmentEventArgs"/> class.
/// </summary>
/// <param name="propertyName">The name of the property whose value was reassigned.</param>
/// <param name="previousValue">The previous value of the reassigned property.</param>
/// <param name="newValue">The new value of the reassigned property.</param>
/// <param name="file">The file associated with the event.</param>
/// <param name="line">The line number (0 if not applicable).</param>
/// <param name="column">The column number (0 if not applicable).</param>
/// <param name="message">The message of the property.</param>
/// <param name="helpKeyword">The help keyword.</param>
/// <param name="senderName">The sender name of the event.</param>
/// <param name="importance">The importance of the message.</param>
public ExtendedPropertyReassignmentEventArgs(
string propertyName,
string previousValue,
string newValue,
string file,
int line,
int column,
string message,
string helpKeyword = null,
string senderName = null,
MessageImportance importance = MessageImportance.Low)
: base(subcategory: null, code: null, file: file, lineNumber: line, columnNumber: column, 0, 0, message, helpKeyword, senderName, importance)
{
PropertyName = propertyName;
PreviousValue = previousValue;
NewValue = newValue;
}

/// <summary>
/// The name of the property whose value was reassigned.
/// </summary>
public string PropertyName { get; set; }

/// <summary>
/// The previous value of the reassigned property.
/// </summary>
public string PreviousValue { get; set; }

/// <summary>
/// The new value of the reassigned property.
/// </summary>
public string NewValue { get; set; }
}
}