add log entry when preprocessing an assembly (#166)

This commit is contained in:
Jesse Plamondon-Willard 2016-11-26 16:00:02 -05:00
parent e9fee3f6fe
commit 7bea3c2ba0
2 changed files with 11 additions and 4 deletions

View File

@ -16,15 +16,20 @@ namespace StardewModdingAPI.Framework
/// <summary>The directory in which to cache data.</summary>
private readonly string CacheDirPath;
/// <summary>Encapsulates monitoring and logging for a given module.</summary>
private readonly IMonitor Monitor;
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="cacheDirPath">The cache directory.</param>
public ModAssemblyLoader(string cacheDirPath)
/// <param name="monitor">Encapsulates monitoring and logging for a given module.</param>
public ModAssemblyLoader(string cacheDirPath, IMonitor monitor)
{
this.CacheDirPath = cacheDirPath;
this.Monitor = monitor;
}
/// <summary>Preprocess an assembly and cache the modified version.</summary>
@ -42,6 +47,8 @@ namespace StardewModdingAPI.Framework
// process assembly if not cached
if (!canUseCache)
{
this.Monitor.Log($"Preprocessing new assembly {assemblyPath}...");
// read assembly definition
AssemblyDefinition definition;
using (Stream readStream = new MemoryStream(assemblyBytes))

View File

@ -298,7 +298,7 @@ namespace StardewModdingAPI
{
Program.Monitor.Log("Loading mods...");
ModAssemblyLoader modAssemblyLoader = new ModAssemblyLoader(Program.CachePath);
ModAssemblyLoader modAssemblyLoader = new ModAssemblyLoader(Program.CachePath, Program.Monitor);
foreach (string directory in Directory.GetDirectories(Program.ModPath))
{
// ignore internal directory
@ -403,7 +403,7 @@ namespace StardewModdingAPI
}
catch (Exception ex)
{
Program.Monitor.Log($"{errorPrefix}: an error occurred while preprocessing '{assemblyPath}'.\n{ex}", LogLevel.Error);
Program.Monitor.Log($"{errorPrefix}: an error occurred while preprocessing '{Path.GetFileName(assemblyPath)}'.\n{ex.GetLogSummary()}", LogLevel.Error);
succeeded = false;
break;
}
@ -426,7 +426,7 @@ namespace StardewModdingAPI
}
catch (Exception ex)
{
Program.Monitor.Log($"{errorPrefix}: an error occurred while optimising the target DLL.\n{ex}", LogLevel.Error);
Program.Monitor.Log($"{errorPrefix}: an error occurred while optimising the target DLL.\n{ex.GetLogSummary()}", LogLevel.Error);
continue;
}