diff --git a/src/Build/BackEnd/Components/Logging/BuildLoggingContext.cs b/src/Build/BackEnd/Components/Logging/BuildLoggingContext.cs index 415a79fa848..dad95be8d26 100644 --- a/src/Build/BackEnd/Components/Logging/BuildLoggingContext.cs +++ b/src/Build/BackEnd/Components/Logging/BuildLoggingContext.cs @@ -59,7 +59,7 @@ public bool IsInProcNode /// The task in which the error occurred internal void LogFatalTaskError(Exception exception, BuildEventFileInfo file, string taskName) { - ErrorUtilities.VerifyThrow(IsValid, "must be valid"); + CheckValidity(); LoggingService.LogFatalTaskError(BuildEventContext, exception, file, taskName); _hasLoggedErrors = true; } diff --git a/src/Build/BackEnd/Components/Logging/LoggingContext.cs b/src/Build/BackEnd/Components/Logging/LoggingContext.cs index 15b6000a7aa..6a8536c913d 100644 --- a/src/Build/BackEnd/Components/Logging/LoggingContext.cs +++ b/src/Build/BackEnd/Components/Logging/LoggingContext.cs @@ -124,7 +124,7 @@ protected set /// string resource arguments internal void LogComment(MessageImportance importance, string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogComment(_eventContext, importance, messageResourceName, messageArgs); } @@ -137,7 +137,7 @@ internal void LogComment(MessageImportance importance, string messageResourceNam /// string resource arguments internal void LogComment(MessageImportance importance, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogBuildEvent(new BuildMessageEventArgs( null, @@ -165,7 +165,7 @@ internal void LogComment(MessageImportance importance, BuildEventFileInfo file, /// message to log internal void LogCommentFromText(MessageImportance importance, string message) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogCommentFromText(_eventContext, importance, message); } @@ -177,7 +177,7 @@ internal void LogCommentFromText(MessageImportance importance, string message) /// Format string arguments internal void LogCommentFromText(MessageImportance importance, string message, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogCommentFromText(_eventContext, importance, message, messageArgs); } @@ -189,7 +189,7 @@ internal void LogCommentFromText(MessageImportance importance, string message, p /// Parameters for the resource string internal void LogError(BuildEventFileInfo file, string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogError(_eventContext, file, messageResourceName, messageArgs); _hasLoggedErrors = true; } @@ -203,7 +203,7 @@ internal void LogError(BuildEventFileInfo file, string messageResourceName, para /// Parameters for the resource string internal void LogErrorWithSubcategory(string subcategoryResourceName, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogError(_eventContext, subcategoryResourceName, file, messageResourceName, messageArgs); _hasLoggedErrors = true; } @@ -218,7 +218,7 @@ internal void LogErrorWithSubcategory(string subcategoryResourceName, BuildEvent /// Error message internal void LogErrorFromText(string subcategoryResourceName, string errorCode, string helpKeyword, BuildEventFileInfo file, string message) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogErrorFromText(_eventContext, subcategoryResourceName, errorCode, helpKeyword, file, message); _hasLoggedErrors = true; } @@ -229,7 +229,7 @@ internal void LogErrorFromText(string subcategoryResourceName, string errorCode, /// The invalid Project File Exception which is to be logged internal void LogInvalidProjectFileError(InvalidProjectFileException invalidProjectFileException) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogInvalidProjectFileError(_eventContext, invalidProjectFileException); _hasLoggedErrors = true; } @@ -243,14 +243,14 @@ internal void LogInvalidProjectFileError(InvalidProjectFileException invalidProj /// The arguments for the error message internal void LogFatalError(Exception exception, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogFatalError(_eventContext, exception, file, messageResourceName, messageArgs); _hasLoggedErrors = true; } internal void LogWarning(string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogWarning(_eventContext, null, BuildEventFileInfo.Empty, messageResourceName, messageArgs); } @@ -263,7 +263,7 @@ internal void LogWarning(string messageResourceName, params object[] messageArgs /// parameters for the string resource internal void LogWarning(string subcategoryResourceName, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogWarning(_eventContext, subcategoryResourceName, file, messageResourceName, messageArgs); } @@ -277,7 +277,7 @@ internal void LogWarning(string subcategoryResourceName, BuildEventFileInfo file /// The message to be logged as a warning internal void LogWarningFromText(string subcategoryResourceName, string warningCode, string helpKeyword, BuildEventFileInfo file, string message) { - ErrorUtilities.VerifyThrow(_isValid, "must be valid"); + CheckValidity(); _loggingService.LogWarningFromText(_eventContext, subcategoryResourceName, warningCode, helpKeyword, file, message); } @@ -287,7 +287,7 @@ internal void LogWarningFromText(string subcategoryResourceName, string warningC /// The event to log internal void LogBuildEvent(BuildEventArgs buildEvent) { - ErrorUtilities.VerifyThrow(IsValid, "must be valid"); + CheckValidity(); LoggingService.LogBuildEvent(buildEvent); } @@ -298,7 +298,7 @@ internal void LogBuildEvent(BuildEventArgs buildEvent) /// The file in which the error occurred internal void LogFatalBuildError(Exception exception, BuildEventFileInfo file) { - ErrorUtilities.VerifyThrow(IsValid, "must be valid"); + CheckValidity(); LoggingService.LogFatalBuildError(BuildEventContext, exception, file); _hasLoggedErrors = true; } @@ -309,8 +309,17 @@ internal void LogFatalBuildError(Exception exception, BuildEventFileInfo file) /// Path to response file internal void LogIncludeFile(string filePath) { - ErrorUtilities.VerifyThrow(IsValid, "must be valid"); + CheckValidity(); _loggingService.LogIncludeFile(BuildEventContext, filePath); } + + private protected void CheckValidity() + { + if (!_isValid) + { + ErrorUtilities.ThrowInternalError("LoggingContext (type: {0}) was not valid during logging attempt.", + this.GetType()); + } + } } } diff --git a/src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs b/src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs index f962f3da74d..262f794f778 100644 --- a/src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs +++ b/src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs @@ -143,7 +143,7 @@ internal void LogTaskBatchFinished(string projectFullPath, bool success) /// The task in which the warning occurred internal void LogTaskWarningFromException(Exception exception, BuildEventFileInfo file, string taskName) { - ErrorUtilities.VerifyThrow(IsValid, "must be valid"); + CheckValidity(); LoggingService.LogTaskWarningFromException(BuildEventContext, exception, file, taskName); }