[Logger] Tell user if there were warnings or errors

This commit is contained in:
Matt Nadareski
2016-10-08 23:33:16 -07:00
parent aac522649c
commit fda3a15f2b

View File

@@ -16,6 +16,7 @@ namespace SabreTools.Helper
{ {
// Private instance variables // Private instance variables
private bool _tofile; private bool _tofile;
private bool _warnings;
private string _filename; private string _filename;
private DateTime _start; private DateTime _start;
private StreamWriter _log; private StreamWriter _log;
@@ -31,6 +32,7 @@ namespace SabreTools.Helper
public Logger(bool tofile, string filename) public Logger(bool tofile, string filename)
{ {
_tofile = tofile; _tofile = tofile;
_warnings = false;
_filename = Path.GetFileNameWithoutExtension(filename) + " (" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ")" + Path.GetExtension(filename); _filename = Path.GetFileNameWithoutExtension(filename) + " (" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ")" + Path.GetExtension(filename);
if (!Directory.Exists(_basepath)) if (!Directory.Exists(_basepath))
@@ -75,6 +77,11 @@ namespace SabreTools.Helper
/// <returns>True if the logging was ended correctly, false otherwise</returns> /// <returns>True if the logging was ended correctly, false otherwise</returns>
public bool Close(bool suppress = false) public bool Close(bool suppress = false)
{ {
if (_warnings)
{
Console.WriteLine("There were warnings or errors in the last run! Check the log for more details");
}
if (!suppress) if (!suppress)
{ {
TimeSpan span = DateTime.Now.Subtract(_start); TimeSpan span = DateTime.Now.Subtract(_start);
@@ -212,6 +219,7 @@ namespace SabreTools.Helper
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public bool Warning(string output, bool appendPrefix = true) public bool Warning(string output, bool appendPrefix = true)
{ {
_warnings = true;
return Log(output, LogLevel.WARNING, appendPrefix); return Log(output, LogLevel.WARNING, appendPrefix);
} }
@@ -223,6 +231,7 @@ namespace SabreTools.Helper
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public bool Error(string output, bool appendPrefix = true) public bool Error(string output, bool appendPrefix = true)
{ {
_warnings = true;
return Log(output, LogLevel.ERROR, appendPrefix); return Log(output, LogLevel.ERROR, appendPrefix);
} }