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

Fix logging context validity check #10348

Merged
merged 1 commit into from
Jul 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public bool IsInProcNode
/// <param name="taskName">The task in which the error occurred</param>
internal void LogFatalTaskError(Exception exception, BuildEventFileInfo file, string taskName)
{
ErrorUtilities.VerifyThrow(IsValid, "must be valid");
CheckValidity();
LoggingService.LogFatalTaskError(BuildEventContext, exception, file, taskName);
_hasLoggedErrors = true;
}
Expand Down
39 changes: 24 additions & 15 deletions src/Build/BackEnd/Components/Logging/LoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected set
/// <param name="messageArgs">string resource arguments</param>
internal void LogComment(MessageImportance importance, string messageResourceName, params object[] messageArgs)
{
ErrorUtilities.VerifyThrow(_isValid, "must be valid");
CheckValidity();
_loggingService.LogComment(_eventContext, importance, messageResourceName, messageArgs);
}

Expand All @@ -137,7 +137,7 @@ internal void LogComment(MessageImportance importance, string messageResourceNam
/// <param name="messageArgs">string resource arguments</param>
internal void LogComment(MessageImportance importance, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
{
ErrorUtilities.VerifyThrow(_isValid, "must be valid");
CheckValidity();

_loggingService.LogBuildEvent(new BuildMessageEventArgs(
null,
Expand Down Expand Up @@ -165,7 +165,7 @@ internal void LogComment(MessageImportance importance, BuildEventFileInfo file,
/// <param name="message">message to log</param>
internal void LogCommentFromText(MessageImportance importance, string message)
{
ErrorUtilities.VerifyThrow(_isValid, "must be valid");
CheckValidity();
_loggingService.LogCommentFromText(_eventContext, importance, message);
}

Expand All @@ -177,7 +177,7 @@ internal void LogCommentFromText(MessageImportance importance, string message)
/// <param name="messageArgs">Format string arguments</param>
internal void LogCommentFromText(MessageImportance importance, string message, params object[] messageArgs)
{
ErrorUtilities.VerifyThrow(_isValid, "must be valid");
CheckValidity();
_loggingService.LogCommentFromText(_eventContext, importance, message, messageArgs);
}

Expand All @@ -189,7 +189,7 @@ internal void LogCommentFromText(MessageImportance importance, string message, p
/// <param name="messageArgs">Parameters for the resource string</param>
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;
}
Expand All @@ -203,7 +203,7 @@ internal void LogError(BuildEventFileInfo file, string messageResourceName, para
/// <param name="messageArgs">Parameters for the resource string</param>
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;
}
Expand All @@ -218,7 +218,7 @@ internal void LogErrorWithSubcategory(string subcategoryResourceName, BuildEvent
/// <param name="message">Error message</param>
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;
}
Expand All @@ -229,7 +229,7 @@ internal void LogErrorFromText(string subcategoryResourceName, string errorCode,
/// <param name="invalidProjectFileException">The invalid Project File Exception which is to be logged</param>
internal void LogInvalidProjectFileError(InvalidProjectFileException invalidProjectFileException)
{
ErrorUtilities.VerifyThrow(_isValid, "must be valid");
CheckValidity();
_loggingService.LogInvalidProjectFileError(_eventContext, invalidProjectFileException);
_hasLoggedErrors = true;
}
Expand All @@ -243,14 +243,14 @@ internal void LogInvalidProjectFileError(InvalidProjectFileException invalidProj
/// <param name="messageArgs">The arguments for the error message</param>
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);
}

Expand All @@ -263,7 +263,7 @@ internal void LogWarning(string messageResourceName, params object[] messageArgs
/// <param name="messageArgs">parameters for the string resource</param>
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);
}

Expand All @@ -277,7 +277,7 @@ internal void LogWarning(string subcategoryResourceName, BuildEventFileInfo file
/// <param name="message">The message to be logged as a warning</param>
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);
}

Expand All @@ -287,7 +287,7 @@ internal void LogWarningFromText(string subcategoryResourceName, string warningC
/// <param name="buildEvent">The event to log</param>
internal void LogBuildEvent(BuildEventArgs buildEvent)
{
ErrorUtilities.VerifyThrow(IsValid, "must be valid");
CheckValidity();
LoggingService.LogBuildEvent(buildEvent);
}

Expand All @@ -298,7 +298,7 @@ internal void LogBuildEvent(BuildEventArgs buildEvent)
/// <param name="file">The file in which the error occurred</param>
internal void LogFatalBuildError(Exception exception, BuildEventFileInfo file)
{
ErrorUtilities.VerifyThrow(IsValid, "must be valid");
CheckValidity();
LoggingService.LogFatalBuildError(BuildEventContext, exception, file);
_hasLoggedErrors = true;
}
Expand All @@ -309,8 +309,17 @@ internal void LogFatalBuildError(Exception exception, BuildEventFileInfo file)
/// <param name="filePath">Path to response file</param>
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());
}
}
}
}
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ internal void LogTaskBatchFinished(string projectFullPath, bool success)
/// <param name="taskName">The task in which the warning occurred</param>
internal void LogTaskWarningFromException(Exception exception, BuildEventFileInfo file, string taskName)
{
ErrorUtilities.VerifyThrow(IsValid, "must be valid");
CheckValidity();
LoggingService.LogTaskWarningFromException(BuildEventContext, exception, file, taskName);
}

Expand Down
Loading