From f7f306a4575df5878056f1a629f4e6ccb9e18d7c Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 29 May 2017 16:20:48 -0500 Subject: [PATCH] (GH-1309) convert trace calls to this.Log.Trace() All current calls to tracing should be simplified so the calls are easier to see. --- .../filesystem/DotNetFileSystem.cs | 10 +++++----- .../infrastructure/services/XmlService.cs | 18 +++++++++--------- .../synchronization/GlobalMutex.cs | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs index fa9819776d..c4455ceed6 100644 --- a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs +++ b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs @@ -413,14 +413,14 @@ public void replace_file(string sourceFilePath, string destinationFilePath, stri { try { - this.Log().Debug(ChocolateyLoggers.Trace, "Backing up '{0}' to '{1}'.".format_with(destinationFilePath, backupFilePath)); + this.Log().Trace("Backing up '{0}' to '{1}'.".format_with(destinationFilePath, backupFilePath)); if (file_exists(backupFilePath)) { - this.Log().Debug(ChocolateyLoggers.Trace, "Deleting existing backup file at '{0}'.".format_with(backupFilePath)); + this.Log().Trace("Deleting existing backup file at '{0}'.".format_with(backupFilePath)); delete_file(backupFilePath); } - this.Log().Debug(ChocolateyLoggers.Trace, "Moving '{0}' to '{1}'.".format_with(destinationFilePath, backupFilePath)); + this.Log().Trace("Moving '{0}' to '{1}'.".format_with(destinationFilePath, backupFilePath)); move_file(destinationFilePath, backupFilePath); } catch (Exception ex) @@ -430,13 +430,13 @@ public void replace_file(string sourceFilePath, string destinationFilePath, stri } // copy source file to destination - this.Log().Debug(ChocolateyLoggers.Trace, "Copying '{0}' to '{1}'.".format_with(sourceFilePath, destinationFilePath)); + this.Log().Trace("Copying '{0}' to '{1}'.".format_with(sourceFilePath, destinationFilePath)); copy_file(sourceFilePath, destinationFilePath, overwriteExisting: true); // delete source file try { - this.Log().Debug(ChocolateyLoggers.Trace, "Removing '{0}'".format_with(sourceFilePath)); + this.Log().Trace("Removing '{0}'".format_with(sourceFilePath)); delete_file(sourceFilePath); } catch (Exception ex) diff --git a/src/chocolatey/infrastructure/services/XmlService.cs b/src/chocolatey/infrastructure/services/XmlService.cs index f2a405bff0..6989f85b8d 100644 --- a/src/chocolatey/infrastructure/services/XmlService.cs +++ b/src/chocolatey/infrastructure/services/XmlService.cs @@ -48,7 +48,7 @@ public XmlType deserialize(string xmlFilePath) return FaultTolerance.retry(3, () => GlobalMutex.enter( () => { - this.Log().Debug(ChocolateyLoggers.Trace, "Entered mutex to deserialize '{0}'".format_with(xmlFilePath)); + this.Log().Trace("Entered mutex to deserialize '{0}'".format_with(xmlFilePath)); return FaultTolerance.try_catch_with_logging_exception( () => @@ -130,13 +130,13 @@ public void serialize(XmlType xmlType, string xmlFilePath, bool isSilen FaultTolerance.retry(3, () => GlobalMutex.enter( () => { - this.Log().Debug(ChocolateyLoggers.Trace, "Entered mutex to serialize '{0}'".format_with(xmlFilePath)); + this.Log().Trace("Entered mutex to serialize '{0}'".format_with(xmlFilePath)); FaultTolerance.try_catch_with_logging_exception( () => { var xmlSerializer = new XmlSerializer(typeof(XmlType)); - this.Log().Debug(ChocolateyLoggers.Trace, "Opening memory stream for xml file creation."); + this.Log().Trace("Opening memory stream for xml file creation."); using (var memoryStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memoryStream, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: true)) { @@ -147,12 +147,12 @@ public void serialize(XmlType xmlType, string xmlFilePath, bool isSilen streamWriter.Flush(); // Grab the hash of both files and compare them. - this.Log().Debug(ChocolateyLoggers.Trace, "Hashing original file at '{0}'".format_with(xmlFilePath)); + this.Log().Trace("Hashing original file at '{0}'".format_with(xmlFilePath)); var originalFileHash = _hashProvider.hash_file(xmlFilePath); memoryStream.Position = 0; if (!originalFileHash.is_equal_to(_hashProvider.hash_stream(memoryStream))) { - this.Log().Debug(ChocolateyLoggers.Trace, "The hashes were different."); + this.Log().Trace("The hashes were different."); // If there wasn't a file there in the first place, just write the new one out directly. if (string.IsNullOrEmpty(originalFileHash)) { @@ -160,7 +160,7 @@ public void serialize(XmlType xmlType, string xmlFilePath, bool isSilen memoryStream.Position = 0; _fileSystem.write_file(xmlFilePath, () => memoryStream); - this.Log().Debug(ChocolateyLoggers.Trace, "Closing xml memory stream."); + this.Log().Trace("Closing xml memory stream."); memoryStream.Close(); streamWriter.Close(); @@ -169,15 +169,15 @@ public void serialize(XmlType xmlType, string xmlFilePath, bool isSilen // Otherwise, create an update file, and resiliently move it into place. var tempUpdateFile = xmlFilePath + "." + Process.GetCurrentProcess().Id + ".update"; - this.Log().Debug(ChocolateyLoggers.Trace, "Creating a temp file at '{0}'".format_with(tempUpdateFile)); + this.Log().Trace("Creating a temp file at '{0}'".format_with(tempUpdateFile)); memoryStream.Position = 0; - this.Log().Debug(ChocolateyLoggers.Trace, "Writing file '{0}'".format_with(tempUpdateFile)); + this.Log().Trace("Writing file '{0}'".format_with(tempUpdateFile)); _fileSystem.write_file(tempUpdateFile, () => memoryStream); memoryStream.Close(); streamWriter.Close(); - this.Log().Debug(ChocolateyLoggers.Trace, "Replacing file '{0}' with '{1}'.".format_with(xmlFilePath, tempUpdateFile)); + this.Log().Trace("Replacing file '{0}' with '{1}'.".format_with(xmlFilePath, tempUpdateFile)); _fileSystem.replace_file(tempUpdateFile, xmlFilePath, xmlFilePath + ".backup"); } } diff --git a/src/chocolatey/infrastructure/synchronization/GlobalMutex.cs b/src/chocolatey/infrastructure/synchronization/GlobalMutex.cs index d15abab5df..8693a756a7 100644 --- a/src/chocolatey/infrastructure/synchronization/GlobalMutex.cs +++ b/src/chocolatey/infrastructure/synchronization/GlobalMutex.cs @@ -37,7 +37,7 @@ public class GlobalMutex : IDisposable private void init_mutex() { - this.Log().Debug(ChocolateyLoggers.Trace, "Initializing global mutex"); + this.Log().Trace("Initializing global mutex"); var mutexId = "Global\\{{{0}}}".format_with(APP_GUID); _mutex = new Mutex(initiallyOwned: false, name: mutexId); @@ -57,7 +57,7 @@ private GlobalMutex(int timeOut) init_mutex(); try { - this.Log().Debug(ChocolateyLoggers.Trace, "Waiting on the mutext handle for {0} milliseconds".format_with(timeOut)); + this.Log().Trace("Waiting on the mutext handle for {0} milliseconds".format_with(timeOut)); _hasHandle = _mutex.WaitOne(timeOut < 0 ? Timeout.Infinite : timeOut, exitContext: false); if (_hasHandle == false)