Skip to content

Commit

Permalink
(GH-1309) convert trace calls to this.Log.Trace()
Browse files Browse the repository at this point in the history
All current calls to tracing should be simplified so the calls are
easier to see.
  • Loading branch information
ferventcoder committed May 29, 2017
1 parent 95f2d0e commit f7f306a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions src/chocolatey/infrastructure/services/XmlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public XmlType deserialize<XmlType>(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(
() =>
Expand Down Expand Up @@ -130,13 +130,13 @@ public void serialize<XmlType>(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))
{
Expand All @@ -147,20 +147,20 @@ public void serialize<XmlType>(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))
{
this.Log().Debug("There was no original file at '{0}'".format_with(xmlFilePath));
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();

Expand All @@ -169,15 +169,15 @@ public void serialize<XmlType>(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");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey/infrastructure/synchronization/GlobalMutex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down

0 comments on commit f7f306a

Please sign in to comment.