From 1e35ad756284d86b2fbc95d86dbc70d81359d594 Mon Sep 17 00:00:00 2001 From: Cormac McCarthy Date: Tue, 22 Oct 2019 12:49:42 -0700 Subject: [PATCH] [999795] Updates to logging (#394) * [999795] Updates to logging * Resolve review feedback --- .../DefaultBuildScriptGenerator.cs | 31 +++---------------- .../DefaultEnvironmentSettingsProvider.cs | 6 ++-- .../DefaultRunScriptGenerator.cs | 4 +-- .../DefaultScriptExecutor.cs | 30 ++---------------- .../DotNetCore/DotnetCoreLanguageDetector.cs | 7 +++-- .../ExplicitProjectFileProvider.cs | 5 +-- .../ProbeAndFindProjectFileProvider.cs | 5 ++- .../Node/NodeDependencyChecker.cs | 3 +- .../Node/NodeLanguageDetector.cs | 5 +-- src/BuildScriptGenerator/Node/NodePlatform.cs | 4 +-- .../Php/PhpLanguageDetector.cs | 5 +-- src/BuildScriptGenerator/Php/PhpPlatform.cs | 3 +- .../Python/PythonLanguageDetector.cs | 7 +++-- .../Commands/BuildCommand.cs | 11 +++---- .../Commands/BuildpackBuildCommand.cs | 2 +- .../Commands/BuildpackDetectCommand.cs | 2 +- .../Commands/ExecCommand.cs | 3 -- src/Common/Extensions/StringExtensions.cs | 27 ++++++++++++++++ 18 files changed, 71 insertions(+), 89 deletions(-) diff --git a/src/BuildScriptGenerator/DefaultBuildScriptGenerator.cs b/src/BuildScriptGenerator/DefaultBuildScriptGenerator.cs index be4150b210..0a900d77f8 100644 --- a/src/BuildScriptGenerator/DefaultBuildScriptGenerator.cs +++ b/src/BuildScriptGenerator/DefaultBuildScriptGenerator.cs @@ -114,7 +114,7 @@ public void GenerateBashScript( { // TODO: Should an UnsupportedLanguageException be thrown here? // Seeing as the issue was that platforms were IDENTIFIED, but no build snippets were emitted from them - LogAndThrowNoPlatformFound(context); + throw new UnsupportedLanguageException(Labels.UnableToDetectLanguageMessage); } } @@ -306,7 +306,7 @@ private void ThrowInvalidLanguageProvided(BuildScriptGeneratorContext context) var languages = _programmingPlatforms.Select(sg => sg.Name); var exc = new UnsupportedLanguageException($"'{context.Language}' platform is not supported. " + $"Supported platforms are: {string.Join(", ", languages)}"); - _logger.LogError(exc, "Exception caught"); + _logger.LogError(exc, $"Exception caught, the given platform '{context.Language}' is not supported."); throw exc; } @@ -314,7 +314,7 @@ private void LogScriptIfGiven(string type, string scriptPath) { if (!string.IsNullOrWhiteSpace(scriptPath)) { - _logger.LogInformation("Using {type} script from {scriptPath}", type, scriptPath); + _logger.LogInformation("Using {type} script", type); } } @@ -368,29 +368,6 @@ private string BuildScriptFromSnippets( return script; } - /// - /// Handles the error when no platform was found, logging information about the repo. - /// - private void LogAndThrowNoPlatformFound(BuildScriptGeneratorContext context) - { - try - { - var directoryStructureData = OryxDirectoryStructureHelper.GetDirectoryStructure( - context.SourceRepo.RootPath); - _logger.LogTrace( - "logDirectoryStructure", - new Dictionary { { "directoryStructure", directoryStructureData } }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Exception caught"); - } - finally - { - throw new UnsupportedLanguageException(Labels.UnableToDetectLanguageMessage); - } - } - /// /// Gets a matching version for the platform given a version in SemVer format. /// If the given version is not supported, an exception is thrown. @@ -406,7 +383,7 @@ private string GetMatchingTargetVersion(IProgrammingPlatform platform, string ta if (string.IsNullOrEmpty(maxSatisfyingVersion)) { var exc = new UnsupportedVersionException(platform.Name, targetVersionSpec, platform.SupportedVersions); - _logger.LogError(exc, "Exception caught"); + _logger.LogError(exc, $"Exception caught, the given version '{targetVersionSpec}' is not supported for platform '{platform.Name}'."); throw exc; } else diff --git a/src/BuildScriptGenerator/DefaultEnvironmentSettingsProvider.cs b/src/BuildScriptGenerator/DefaultEnvironmentSettingsProvider.cs index 158c1daf95..309702a8d8 100644 --- a/src/BuildScriptGenerator/DefaultEnvironmentSettingsProvider.cs +++ b/src/BuildScriptGenerator/DefaultEnvironmentSettingsProvider.cs @@ -10,6 +10,7 @@ using System.Linq; using Microsoft.Extensions.Logging; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator { @@ -95,8 +96,9 @@ internal void ReadSettingsFromFile(IDictionary settings) return; } - foreach (var line in lines) + for (int idx = 0; idx < lines.Length;idx++) { + var line = lines[idx]; // Ignore comments and blank lines if (line.StartsWith("#") || string.IsNullOrEmpty(line)) { @@ -111,7 +113,7 @@ internal void ReadSettingsFromFile(IDictionary settings) else { _logger.LogDebug( - $"Ignoring invalid line '{line}' in '{Constants.BuildEnvironmentFileName}' file."); + $"Ignoring invalid line number '{idx + 1}' in '{Constants.BuildEnvironmentFileName.Hash()}' file."); } } } diff --git a/src/BuildScriptGenerator/DefaultRunScriptGenerator.cs b/src/BuildScriptGenerator/DefaultRunScriptGenerator.cs index 0f158afe91..c0f448e233 100644 --- a/src/BuildScriptGenerator/DefaultRunScriptGenerator.cs +++ b/src/BuildScriptGenerator/DefaultRunScriptGenerator.cs @@ -99,8 +99,8 @@ private string RunStartupScriptGeneratorForPlatform(IProgrammingPlatform plat, R if (exitCode != ProcessConstants.ExitSuccess) { - _logger.LogError("{scriptGenPath} returned {exitCode}", scriptGenPath, exitCode); - throw new Exception("{scriptGenPath} failed"); + _logger.LogError("Generated run script returned exit code '{exitCode}'", exitCode); + throw new Exception($"{scriptGenPath} failed"); } return File.ReadAllText(_tempScriptPath); diff --git a/src/BuildScriptGenerator/DefaultScriptExecutor.cs b/src/BuildScriptGenerator/DefaultScriptExecutor.cs index d85eb6af93..1f4b2e2fed 100644 --- a/src/BuildScriptGenerator/DefaultScriptExecutor.cs +++ b/src/BuildScriptGenerator/DefaultScriptExecutor.cs @@ -30,34 +30,10 @@ public int ExecuteScript( int exitCode = ProcessHelper.TrySetExecutableMode(scriptPath, workingDirectory); if (exitCode != ProcessConstants.ExitSuccess) { - _logger.LogError( - "Failed to set execute permission on script {scriptPath} ({exitCode})", - scriptPath, - exitCode); return exitCode; } - exitCode = ExecuteScriptInternal(scriptPath, args, workingDirectory, stdOutHandler, stdErrHandler); - if (exitCode != ProcessConstants.ExitSuccess) - { - try - { - var directoryStructureData = OryxDirectoryStructureHelper.GetDirectoryStructure(workingDirectory); - _logger.LogTrace( - "logDirectoryStructure", - new Dictionary { { "directoryStructure", directoryStructureData } }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Exception caught"); - } - finally - { - _logger.LogError("Execution of script {scriptPath} failed ({exitCode})", scriptPath, exitCode); - } - } - - return exitCode; + return ExecuteScriptInternal(scriptPath, args, workingDirectory, stdOutHandler, stdErrHandler); } protected virtual int ExecuteScriptInternal( @@ -68,9 +44,7 @@ protected virtual int ExecuteScriptInternal( DataReceivedEventHandler stdErrHandler) { int exitCode; - using (var timedEvent = _logger.LogTimedEvent( - "ExecuteScript", - new Dictionary { { "scriptPath", scriptPath } })) + using (var timedEvent = _logger.LogTimedEvent("ExecuteScript")) { exitCode = ProcessHelper.RunProcess( scriptPath, diff --git a/src/BuildScriptGenerator/DotNetCore/DotnetCoreLanguageDetector.cs b/src/BuildScriptGenerator/DotNetCore/DotnetCoreLanguageDetector.cs index 7d067b1799..2c1714f942 100644 --- a/src/BuildScriptGenerator/DotNetCore/DotnetCoreLanguageDetector.cs +++ b/src/BuildScriptGenerator/DotNetCore/DotnetCoreLanguageDetector.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; +using Microsoft.Oryx.Common.Extensions; using Newtonsoft.Json; namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore @@ -52,7 +53,7 @@ public LanguageDetectorResult Detect(ScriptGeneratorContext context) if (string.IsNullOrEmpty(targetFramework)) { _logger.LogDebug( - $"Could not find 'TargetFramework' element in the project file '{projectFile}'."); + $"Could not find 'TargetFramework' element in the project file."); return null; } @@ -137,7 +138,7 @@ private string VerifyAndResolveVersion(string version) DotNetCoreConstants.LanguageName, version, _versionProvider.SupportedDotNetCoreVersions); - _logger.LogError(exc, "Exception caught"); + _logger.LogError(exc, $"Exception caught, the given version '{version}' is not supported for the .NET Core platform."); throw exc; } @@ -161,7 +162,7 @@ private dynamic GetGlobalJsonObject(ISourceRepo sourceRepo) // in the package.json file. _logger.LogError( ex, - $"An error occurred while trying to deserialize {DotNetCoreConstants.GlobalJsonFileName}"); + $"An error occurred while trying to deserialize {DotNetCoreConstants.GlobalJsonFileName.Hash()}"); } return globalJson; diff --git a/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ExplicitProjectFileProvider.cs b/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ExplicitProjectFileProvider.cs index da6661ebfc..9a784f0fe4 100644 --- a/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ExplicitProjectFileProvider.cs +++ b/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ExplicitProjectFileProvider.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore { @@ -43,11 +44,11 @@ public string GetRelativePathToProjectFile(ScriptGeneratorContext context) var projectFile = Path.Combine(context.SourceRepo.RootPath, projectFileWithRelativePath); if (context.SourceRepo.FileExists(projectFile)) { - _logger.LogDebug($"Using the project file '{projectFile}' to build."); + _logger.LogDebug($"Using the given .NET Core project file to build."); } else { - _logger.LogWarning($"Could not find the project file '{projectFile}'."); + _logger.LogWarning($"Could not find the .NET Core project file."); throw new InvalidUsageException( string.Format(Resources.Labels.DotNetCoreCouldNotFindProjectFileToBuild, projectFile)); } diff --git a/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ProbeAndFindProjectFileProvider.cs b/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ProbeAndFindProjectFileProvider.cs index 72b4b734bf..554c5f3a4d 100644 --- a/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ProbeAndFindProjectFileProvider.cs +++ b/src/BuildScriptGenerator/DotNetCore/ProjectFileProviders/ProbeAndFindProjectFileProvider.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; using Microsoft.Oryx.BuildScriptGenerator.Resources; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore { @@ -93,9 +94,7 @@ public string GetRelativePathToProjectFile(ScriptGeneratorContext context) if (projectFile == null) { - _logger.LogDebug( - $"Could not find a project file to build. Available project files: " + - $"{string.Join(',', allProjects)}"); + _logger.LogDebug("Could not find a .NET Core project file to build."); return null; } diff --git a/src/BuildScriptGenerator/Node/NodeDependencyChecker.cs b/src/BuildScriptGenerator/Node/NodeDependencyChecker.cs index d2b0d4b452..7ee6053145 100644 --- a/src/BuildScriptGenerator/Node/NodeDependencyChecker.cs +++ b/src/BuildScriptGenerator/Node/NodeDependencyChecker.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.Node { @@ -32,7 +33,7 @@ public IEnumerable CheckSourceRepo(ISourceRepo repo) dynamic packageJson = NodePlatform.GetPackageJsonObject(repo, null); if (packageJson == null) { - _logger.LogDebug("packageJson is null; skipping checking for superseded packages"); + _logger.LogDebug($"{NodeConstants.PackageJsonFileName.Hash()} is null; skipping checking for superseded packages"); return Enumerable.Empty(); } diff --git a/src/BuildScriptGenerator/Node/NodeLanguageDetector.cs b/src/BuildScriptGenerator/Node/NodeLanguageDetector.cs index 158c64a876..b82f68af9a 100644 --- a/src/BuildScriptGenerator/Node/NodeLanguageDetector.cs +++ b/src/BuildScriptGenerator/Node/NodeLanguageDetector.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.Node { @@ -87,7 +88,7 @@ public LanguageDetectorResult Detect(ScriptGeneratorContext context) { _logger.LogDebug( "App in repo is not a Node.js app as it has the file {iisStartupFile}", - iisStartupFile); + iisStartupFile.Hash()); return null; } } @@ -141,7 +142,7 @@ private string DetectNodeVersion(dynamic packageJson) NodeConstants.NodeJsName, nodeVersionRange, _versionProvider.SupportedNodeVersions); - _logger.LogError(exc, "Exception caught"); + _logger.LogError(exc, $"Exception caught, the version '{nodeVersionRange}' is not supported for the node platform."); throw exc; } } diff --git a/src/BuildScriptGenerator/Node/NodePlatform.cs b/src/BuildScriptGenerator/Node/NodePlatform.cs index 54b300c40b..86de36babc 100644 --- a/src/BuildScriptGenerator/Node/NodePlatform.cs +++ b/src/BuildScriptGenerator/Node/NodePlatform.cs @@ -258,7 +258,7 @@ public void SetRequiredTools( } else { - _logger.LogDebug($"packageJson is null; skipping setting {NodeConstants.NpmToolName} tool"); + _logger.LogDebug($"{NodeConstants.PackageJsonFileName} is null; skipping setting {NodeConstants.NpmToolName} tool"); } } @@ -319,7 +319,7 @@ internal static dynamic GetPackageJsonObject(ISourceRepo sourceRepo, ILogger log // This prevents Oryx from erroring out when Node.js itself might be able to tolerate the file. logger.LogWarning( exc, - $"Exception caught while trying to deserialize {NodeConstants.PackageJsonFileName}"); + $"Exception caught while trying to deserialize {NodeConstants.PackageJsonFileName.Hash()}"); } return packageJson; diff --git a/src/BuildScriptGenerator/Php/PhpLanguageDetector.cs b/src/BuildScriptGenerator/Php/PhpLanguageDetector.cs index 025956bc96..e995b70d21 100644 --- a/src/BuildScriptGenerator/Php/PhpLanguageDetector.cs +++ b/src/BuildScriptGenerator/Php/PhpLanguageDetector.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Options; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; using Microsoft.Oryx.BuildScriptGenerator.SourceRepo; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.Php { @@ -51,7 +52,7 @@ public LanguageDetectorResult Detect(ScriptGeneratorContext context) // some errors in the composer.json file. _logger.LogWarning( ex, - $"Exception caught while trying to deserialize {PhpConstants.ComposerFileName}"); + $"Exception caught while trying to deserialize {PhpConstants.ComposerFileName.Hash()}"); } string runtimeVersion = VerifyAndResolveVersion(composerFile?.require?.php?.Value as string); @@ -78,7 +79,7 @@ private string VerifyAndResolveVersion(string version) PhpConstants.PhpName, version, _versionProvider.SupportedPhpVersions); - _logger.LogError(exc, "Exception caught"); + _logger.LogError(exc, $"Exception caught, the version '{version}' is not supported for the PHP platform."); throw exc; } diff --git a/src/BuildScriptGenerator/Php/PhpPlatform.cs b/src/BuildScriptGenerator/Php/PhpPlatform.cs index cc3969e0ff..939466e60e 100644 --- a/src/BuildScriptGenerator/Php/PhpPlatform.cs +++ b/src/BuildScriptGenerator/Php/PhpPlatform.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Options; using Microsoft.Oryx.BuildScriptGenerator.SourceRepo; using Microsoft.Oryx.Common; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.Php { @@ -66,7 +67,7 @@ public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorCon { // Leave malformed composer.json files for Composer to handle. // This prevents Oryx from erroring out when Composer itself might be able to tolerate the file. - _logger.LogWarning(exc, $"Exception caught while trying to deserialize {PhpConstants.ComposerFileName}"); + _logger.LogWarning(exc, $"Exception caught while trying to deserialize {PhpConstants.ComposerFileName.Hash()}"); } } diff --git a/src/BuildScriptGenerator/Python/PythonLanguageDetector.cs b/src/BuildScriptGenerator/Python/PythonLanguageDetector.cs index 78cf80148d..ce7e1ad375 100644 --- a/src/BuildScriptGenerator/Python/PythonLanguageDetector.cs +++ b/src/BuildScriptGenerator/Python/PythonLanguageDetector.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Oryx.BuildScriptGenerator.Exceptions; +using Microsoft.Oryx.Common.Extensions; namespace Microsoft.Oryx.BuildScriptGenerator.Python { @@ -82,7 +83,7 @@ private string VerifyAndResolveVersion(string version) PythonConstants.PythonName, version, _versionProvider.SupportedPythonVersions); - _logger.LogError(exc, "Exception caught"); + _logger.LogError(exc, $"Exception caught, the version '{version}' is not supported for the Python platform."); throw exc; } @@ -107,7 +108,7 @@ private string DetectPythonVersionFromRuntimeFile(ISourceRepo sourceRepo) _logger.LogDebug( "Prefix {verPrefix} was not found in file {rtFileName}", versionPrefix, - PythonConstants.RuntimeFileName); + PythonConstants.RuntimeFileName.Hash()); return null; } @@ -120,7 +121,7 @@ private string DetectPythonVersionFromRuntimeFile(ISourceRepo sourceRepo) _logger.LogError( ex, "An error occurred while reading file {rtFileName}", - PythonConstants.RuntimeFileName); + PythonConstants.RuntimeFileName.Hash()); } } else diff --git a/src/BuildScriptGeneratorCli/Commands/BuildCommand.cs b/src/BuildScriptGeneratorCli/Commands/BuildCommand.cs index 4b530ae54d..5b4b14a881 100644 --- a/src/BuildScriptGeneratorCli/Commands/BuildCommand.cs +++ b/src/BuildScriptGeneratorCli/Commands/BuildCommand.cs @@ -192,7 +192,10 @@ internal int Execute( // Write build script to selected path File.WriteAllText(buildScriptPath, scriptContent); logger.LogTrace("Build script written to file"); - logger.LogDebug("Build script content:\n" + scriptContent); + if (DebugMode) + { + console.WriteLine($"Build script content:\n{scriptContent}"); + } var buildEventProps = new Dictionary() { @@ -270,8 +273,6 @@ internal int Execute( timedEvent.AddProperty("exitCode", exitCode.ToString()); } - logger.LogLongMessage(LogLevel.Debug, "Build script output", buildScriptOutput.ToString()); - if (exitCode != ProcessConstants.ExitSuccess) { logger.LogError("Build script exited with {exitCode}", exitCode); @@ -312,9 +313,7 @@ internal override bool IsValidInput(IServiceProvider serviceProvider, IConsole c if (IsSubDirectory(options.IntermediateDir, options.SourceDir)) { logger.LogError( - "Intermediate directory {intermediateDir} cannot be a child of {srcDir}", - options.IntermediateDir, - options.SourceDir); + "Intermediate directory cannot be a child of the source directory."); console.WriteErrorLine( $"Intermediate directory '{options.IntermediateDir}' cannot be a " + $"sub-directory of source directory '{options.SourceDir}'."); diff --git a/src/BuildScriptGeneratorCli/Commands/BuildpackBuildCommand.cs b/src/BuildScriptGeneratorCli/Commands/BuildpackBuildCommand.cs index 6ea16a8e6d..180f815288 100644 --- a/src/BuildScriptGeneratorCli/Commands/BuildpackBuildCommand.cs +++ b/src/BuildScriptGeneratorCli/Commands/BuildpackBuildCommand.cs @@ -35,7 +35,7 @@ internal override bool IsValidInput(IServiceProvider serviceProvider, IConsole c LayersDir = Path.GetFullPath(LayersDir); if (!Directory.Exists(LayersDir)) { - logger.LogError("Could not find layers directory {layersDir}", LayersDir); + logger.LogError("Could not find provided layers directory."); console.WriteErrorLine($"Could not find layers directory '{LayersDir}'."); result = false; } diff --git a/src/BuildScriptGeneratorCli/Commands/BuildpackDetectCommand.cs b/src/BuildScriptGeneratorCli/Commands/BuildpackDetectCommand.cs index e0d603ea91..f3c6d325fa 100644 --- a/src/BuildScriptGeneratorCli/Commands/BuildpackDetectCommand.cs +++ b/src/BuildScriptGeneratorCli/Commands/BuildpackDetectCommand.cs @@ -42,7 +42,7 @@ internal override bool IsValidInput(IServiceProvider serviceProvider, IConsole c // Set from ConfigureBuildScriptGeneratorOptions if (!Directory.Exists(options.SourceDir)) { - logger.LogError("Could not find the source directory {srcDir}", options.SourceDir); + logger.LogError("Could not find the source directory."); console.WriteErrorLine($"Could not find the source directory '{options.SourceDir}'."); result = false; } diff --git a/src/BuildScriptGeneratorCli/Commands/ExecCommand.cs b/src/BuildScriptGeneratorCli/Commands/ExecCommand.cs index c327919c21..04b918f8c2 100644 --- a/src/BuildScriptGeneratorCli/Commands/ExecCommand.cs +++ b/src/BuildScriptGeneratorCli/Commands/ExecCommand.cs @@ -42,8 +42,6 @@ internal override int Execute(IServiceProvider serviceProvider, IConsole console } var shellPath = env.GetEnvironmentVariable("BASH") ?? FilePaths.Bash; - logger.LogInformation("Using shell {shell}", shellPath); - var ctx = BuildScriptGenerator.CreateContext(serviceProvider, operationId: null); ctx.DisableMultiPlatformBuild = false; var tools = generator.GetRequiredToolVersions(ctx); @@ -62,7 +60,6 @@ internal override int Execute(IServiceProvider serviceProvider, IConsole console } var script = scriptBuilder.AddCommand(Command).ToString(); - logger.LogDebug("Script content:\n{script}", script); // Create temporary file to store script var tempScriptPath = Path.GetTempFileName(); diff --git a/src/Common/Extensions/StringExtensions.cs b/src/Common/Extensions/StringExtensions.cs index 90716812e4..d8597f3822 100644 --- a/src/Common/Extensions/StringExtensions.cs +++ b/src/Common/Extensions/StringExtensions.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -74,5 +75,31 @@ public static IList Chunkify(this string str, int maxLength) return result; } + + /// + /// Hash a string using SHA-256 + /// + /// The string to hash. + /// The SHA-256 hash of the given string. + public static string Hash(this string str) + { + if (string.IsNullOrEmpty(str)) + { + return str; + } + + using (var sha = SHA256.Create()) + { + var bytes = Encoding.UTF8.GetBytes(str); + var hash = sha.ComputeHash(bytes); + var result = new StringBuilder(); + foreach (var x in bytes) + { + result.AppendFormat("{0:x2}", x); + } + + return result.ToString(); + } + } } }