Instance logging with backing static class instead of Global

This commit is contained in:
Matt Nadareski
2020-10-07 15:42:30 -07:00
parent 348a2a2bcb
commit b7db9f7f14
69 changed files with 1034 additions and 834 deletions

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.Logging;
using NaturalSort;
namespace SabreTools.Library.IO
@@ -91,7 +91,7 @@ namespace SabreTools.Library.IO
}
catch (Exception ex)
{
Globals.Logger.Error(ex, $"An exception occurred getting the full path for '{input}'");
LoggerImpl.Error(ex, $"An exception occurred getting the full path for '{input}'");
continue;
}
@@ -106,11 +106,11 @@ namespace SabreTools.Library.IO
}
catch (PathTooLongException ex)
{
Globals.Logger.Warning(ex, $"The path for '{dir}' was too long");
LoggerImpl.Warning(ex, $"The path for '{dir}' was too long");
}
catch (Exception ex)
{
Globals.Logger.Error(ex, $"An exception occurred processing '{dir}'");
LoggerImpl.Error(ex, $"An exception occurred processing '{dir}'");
}
}
}
@@ -187,7 +187,7 @@ namespace SabreTools.Library.IO
}
catch (Exception ex)
{
Globals.Logger.Error(ex, $"An exception occurred getting the full path for '{input}'");
LoggerImpl.Error(ex, $"An exception occurred getting the full path for '{input}'");
continue;
}
@@ -202,11 +202,11 @@ namespace SabreTools.Library.IO
}
catch (PathTooLongException ex)
{
Globals.Logger.Warning(ex, $"The path for '{file}' was too long");
LoggerImpl.Warning(ex, $"The path for '{file}' was too long");
}
catch (Exception ex)
{
Globals.Logger.Error(ex, $"An exception occurred processing '{file}'");
LoggerImpl.Error(ex, $"An exception occurred processing '{file}'");
}
}
}
@@ -218,11 +218,11 @@ namespace SabreTools.Library.IO
}
catch (PathTooLongException ex)
{
Globals.Logger.Warning(ex, $"The path for '{input}' was too long");
LoggerImpl.Warning(ex, $"The path for '{input}' was too long");
}
catch (Exception ex)
{
Globals.Logger.Error(ex, $"An exception occurred processing '{input}'");
LoggerImpl.Error(ex, $"An exception occurred processing '{input}'");
}
}
}

View File

@@ -8,6 +8,7 @@ using System.Xml.Schema;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.FileTypes;
using SabreTools.Library.Logging;
using SabreTools.Library.Skippers;
namespace SabreTools.Library.IO
@@ -17,6 +18,15 @@ namespace SabreTools.Library.IO
/// </summary>
public static class FileExtensions
{
#region Logging
/// <summary>
/// Logging object
/// </summary>
private static Logger logger = new Logger();
#endregion
/// <summary>
/// Add an aribtrary number of bytes to the inputted file
/// </summary>
@@ -59,12 +69,12 @@ namespace SabreTools.Library.IO
string ext = PathExtensions.GetNormalizedExtension(filename);
// Read the input file, if possible
Globals.Logger.Verbose($"Attempting to read file to get format: {filename}");
logger.Verbose($"Attempting to read file to get format: {filename}");
// Check if file exists
if (!File.Exists(filename))
{
Globals.Logger.Warning($"File '{filename}' could not read from!");
logger.Warning($"File '{filename}' could not read from!");
return 0;
}
@@ -189,7 +199,7 @@ namespace SabreTools.Library.IO
}
catch (Exception ex)
{
Globals.Logger.Warning(ex, $"An exception occurred trying to figure out the format of '{filename}'");
logger.Warning(ex, $"An exception occurred trying to figure out the format of '{filename}'");
return 0;
}
}
@@ -305,7 +315,7 @@ namespace SabreTools.Library.IO
}
catch (Exception ex)
{
Globals.Logger.Warning(ex, $"An exception occurred determining file type of '{input}'");
logger.Warning(ex, $"An exception occurred determining file type of '{input}'");
}
return outFileType;
@@ -401,12 +411,12 @@ namespace SabreTools.Library.IO
/// <returns>The IniReader representing the (possibly converted) file, null otherwise</returns>
public static IniReader GetIniReader(this string filename, bool validateRows)
{
Globals.Logger.Verbose($"Attempting to read file: {filename}");
logger.Verbose($"Attempting to read file: {filename}");
// Check if file exists
if (!File.Exists(filename))
{
Globals.Logger.Warning($"File '{filename}' could not read from!");
logger.Warning($"File '{filename}' could not read from!");
return null;
}
@@ -424,12 +434,12 @@ namespace SabreTools.Library.IO
/// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns>
public static XmlReader GetXmlTextReader(this string filename)
{
Globals.Logger.Verbose($"Attempting to read file: {filename}");
logger.Verbose($"Attempting to read file: {filename}");
// Check if file exists
if (!File.Exists(filename))
{
Globals.Logger.Warning($"File '{filename}' could not read from!");
logger.Warning($"File '{filename}' could not read from!");
return null;
}

View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.FileTypes;
using SabreTools.Library.Logging;
using SabreTools.Library.Tools;
using Compress.ThreadReaders;
@@ -161,7 +162,7 @@ namespace SabreTools.Library.IO
}
catch (IOException ex)
{
Globals.Logger.Warning(ex, "An exception occurred during hashing.");
LoggerImpl.Warning(ex, "An exception occurred during hashing.");
return new BaseFile();
}
finally
@@ -194,11 +195,11 @@ namespace SabreTools.Library.IO
}
catch (NotSupportedException ex)
{
Globals.Logger.Verbose(ex, "Stream does not support seeking to starting offset. Stream position not changed");
LoggerImpl.Verbose(ex, "Stream does not support seeking to starting offset. Stream position not changed");
}
catch (NotImplementedException ex)
{
Globals.Logger.Warning(ex, "Stream does not support seeking to starting offset. Stream position not changed");
LoggerImpl.Warning(ex, "Stream does not support seeking to starting offset. Stream position not changed");
}
return -1;