mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Support ancient .NET in Logging
This commit is contained in:
@@ -22,7 +22,7 @@ namespace SabreTools.Logging
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if we're logging to file or not
|
/// Determines if we're logging to file or not
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool LogToFile { get { return !string.IsNullOrWhiteSpace(Filename); } }
|
public static bool LogToFile { get { return !string.IsNullOrEmpty(Filename); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Optional output log directory
|
/// Optional output log directory
|
||||||
@@ -118,7 +118,11 @@ namespace SabreTools.Logging
|
|||||||
Directory.CreateDirectory(LogDirectory);
|
Directory.CreateDirectory(LogDirectory);
|
||||||
|
|
||||||
FileStream logfile = File.Create(Path.Combine(LogDirectory ?? string.Empty, Filename ?? string.Empty));
|
FileStream logfile = File.Create(Path.Combine(LogDirectory ?? string.Empty, Filename ?? string.Empty));
|
||||||
|
#if NET20 || NET35 || NET40
|
||||||
|
_log = new StreamWriter(logfile, Encoding.UTF8, 4096)
|
||||||
|
#else
|
||||||
_log = new StreamWriter(logfile, Encoding.UTF8, 4096, true)
|
_log = new StreamWriter(logfile, Encoding.UTF8, 4096, true)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
AutoFlush = true
|
AutoFlush = true
|
||||||
};
|
};
|
||||||
@@ -151,12 +155,16 @@ namespace SabreTools.Logging
|
|||||||
|
|
||||||
TimeSpan span = DateTime.Now.Subtract(StartTime);
|
TimeSpan span = DateTime.Now.Subtract(StartTime);
|
||||||
|
|
||||||
|
#if NET20 || NET35
|
||||||
|
string total = span.ToString();
|
||||||
|
#else
|
||||||
// Special case for multi-day runs
|
// Special case for multi-day runs
|
||||||
string total;
|
string total;
|
||||||
if (span >= TimeSpan.FromDays(1))
|
if (span >= TimeSpan.FromDays(1))
|
||||||
total = span.ToString(@"d\:hh\:mm\:ss");
|
total = span.ToString(@"d\:hh\:mm\:ss");
|
||||||
else
|
else
|
||||||
total = span.ToString(@"hh\:mm\:ss");
|
total = span.ToString(@"hh\:mm\:ss");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!LogToFile)
|
if (!LogToFile)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user