From 7d2fef21f6a6c5741d64e53a07795899fe70db65 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Fri, 6 Dec 2024 17:14:01 +0100 Subject: [PATCH 1/4] add ExtendedPropertyInitialValueSetEventArgs that contains information about property location --- .../BinaryLogger/BuildEventArgsReader.cs | 5 +- ...xtendedPropertyInitialValueSetEventArgs.cs | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/StructuredLogger/BinaryLogger/ExtendedPropertyInitialValueSetEventArgs.cs diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs index 3e633070..5629d4a6 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs @@ -1401,10 +1401,13 @@ private BuildEventArgs ReadPropertyInitialValueSetEventArgs() string propertyValue = ReadDeduplicatedString(); string propertySource = ReadDeduplicatedString(); - var e = new PropertyInitialValueSetEventArgs( + var e = new ExtendedPropertyInitialValueSetEventArgs( propertyName, propertyValue, propertySource, + fields.File, + fields.LineNumber, + fields.ColumnNumber, fields.Message, fields.HelpKeyword, fields.SenderName, diff --git a/src/StructuredLogger/BinaryLogger/ExtendedPropertyInitialValueSetEventArgs.cs b/src/StructuredLogger/BinaryLogger/ExtendedPropertyInitialValueSetEventArgs.cs new file mode 100644 index 00000000..fe649e2c --- /dev/null +++ b/src/StructuredLogger/BinaryLogger/ExtendedPropertyInitialValueSetEventArgs.cs @@ -0,0 +1,53 @@ +using Microsoft.Build.Framework; + +namespace StructuredLogger.BinaryLogger +{ + internal class ExtendedPropertyInitialValueSetEventArgs : BuildMessageEventArgs + { + /// + /// Creates an instance of the class. + /// + /// The name of the property. + /// The value of the property. + /// The source of the property. + /// The file associated with the event. + /// The line number (0 if not applicable). + /// The column number (0 if not applicable). + /// The message of the property. + /// The help keyword. + /// The sender name of the event. + /// The importance of the message. + 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; + } + + /// + /// The name of the property. + /// + public string PropertyName { get; set; } + + /// + /// The value of the property. + /// + public string PropertyValue { get; set; } + + /// + /// The source of the property. + /// + public string PropertySource { get; set; } + } +} From ef4324a3bb3fe627ac756ed98a535b51089f9a94 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Tue, 10 Dec 2024 22:58:24 +0100 Subject: [PATCH 2/4] change message formatting and bump the version --- .../BinaryLogger/BinaryLogger.cs | 4 +- .../BinaryLogger/BuildEventArgsReader.cs | 46 +++++++++++----- .../ExtendedPropertyReassignmentEventArgs.cs | 53 +++++++++++++++++++ 3 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 src/StructuredLogger/BinaryLogger/ExtendedPropertyReassignmentEventArgs.cs diff --git a/src/StructuredLogger/BinaryLogger/BinaryLogger.cs b/src/StructuredLogger/BinaryLogger/BinaryLogger.cs index aecfac2b..09e7be2a 100644 --- a/src/StructuredLogger/BinaryLogger/BinaryLogger.cs +++ b/src/StructuredLogger/BinaryLogger/BinaryLogger.cs @@ -78,6 +78,8 @@ 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. @@ -85,7 +87,7 @@ public sealed class BinaryLogger : ILogger // 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 diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs index 5629d4a6..f7f5d476 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs @@ -1357,23 +1357,36 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs() string newValue = ReadDeduplicatedString(); string location = ReadDeduplicatedString(); - string message = fields.Message; - if (_fileFormatVersion >= 13) + string message = null; + if (_fileFormatVersion >= 13 && _fileFormatVersion < 25) { message = GetPropertyReassignmentMessage(propertyName, newValue, previousValue, location); } + else if (_fileFormatVersion >= 25) + { + 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; } @@ -1401,6 +1414,15 @@ private BuildEventArgs ReadPropertyInitialValueSetEventArgs() string propertyValue = ReadDeduplicatedString(); string propertySource = ReadDeduplicatedString(); + 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, @@ -1408,7 +1430,7 @@ private BuildEventArgs ReadPropertyInitialValueSetEventArgs() fields.File, fields.LineNumber, fields.ColumnNumber, - fields.Message, + message, fields.HelpKeyword, fields.SenderName, fields.Importance); diff --git a/src/StructuredLogger/BinaryLogger/ExtendedPropertyReassignmentEventArgs.cs b/src/StructuredLogger/BinaryLogger/ExtendedPropertyReassignmentEventArgs.cs new file mode 100644 index 00000000..51e434fb --- /dev/null +++ b/src/StructuredLogger/BinaryLogger/ExtendedPropertyReassignmentEventArgs.cs @@ -0,0 +1,53 @@ +using Microsoft.Build.Framework; + +namespace StructuredLogger.BinaryLogger +{ + internal class ExtendedPropertyReassignmentEventArgs : BuildMessageEventArgs + { + /// + /// Creates an instance of the class. + /// + /// The name of the property whose value was reassigned. + /// The previous value of the reassigned property. + /// The new value of the reassigned property. + /// The file associated with the event. + /// The line number (0 if not applicable). + /// The column number (0 if not applicable). + /// The message of the property. + /// The help keyword. + /// The sender name of the event. + /// The importance of the message. + 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; + } + + /// + /// The name of the property whose value was reassigned. + /// + public string PropertyName { get; set; } + + /// + /// The previous value of the reassigned property. + /// + public string PreviousValue { get; set; } + + /// + /// The new value of the reassigned property. + /// + public string NewValue { get; set; } + } +} From ce50243df7ab3dd6a0a4291df7c00ee1100b4c9b Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Wed, 11 Dec 2024 16:31:45 +0100 Subject: [PATCH 3/4] remove extra change --- src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs index f7f5d476..9995c069 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs @@ -1357,7 +1357,7 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs() string newValue = ReadDeduplicatedString(); string location = ReadDeduplicatedString(); - string message = null; + string message = fields.Message; if (_fileFormatVersion >= 13 && _fileFormatVersion < 25) { message = GetPropertyReassignmentMessage(propertyName, newValue, previousValue, location); From aedfe3969bd311af0e28299bd479a92a220f0d94 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Wed, 11 Dec 2024 16:43:01 +0100 Subject: [PATCH 4/4] add null check --- src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs index 9995c069..aca0b659 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs @@ -1362,7 +1362,7 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs() { message = GetPropertyReassignmentMessage(propertyName, newValue, previousValue, location); } - else if (_fileFormatVersion >= 25) + 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(