Support for creating log path and having no log file

This commit is contained in:
2014-05-16 14:13:39 -04:00
parent 91dcbf5116
commit 83f6aaaf61

View File

@@ -63,6 +63,11 @@ namespace Common.Debug
{ {
_echoToConsole = echoToConsole; _echoToConsole = echoToConsole;
if (!Directory.Exists(logPath))
Directory.CreateDirectory(logPath);
if (!string.IsNullOrEmpty(logPath))
{
// Use the file name template build the base file name // Use the file name template build the base file name
_mainFileName = string.Format(_fileNameTemplate, rootName, uniqueId); _mainFileName = string.Format(_fileNameTemplate, rootName, uniqueId);
@@ -87,6 +92,7 @@ namespace Common.Debug
// Setup the debug listener // Setup the debug listener
Trace.Listeners.Add(_traceListener); Trace.Listeners.Add(_traceListener);
}
_initialized = true; _initialized = true;
@@ -103,6 +109,8 @@ namespace Common.Debug
// Flush the trace // Flush the trace
Trace.Flush(); Trace.Flush();
if (_traceListener != null)
{
// Remove the listener // Remove the listener
Trace.Listeners.Remove(_traceListener); Trace.Listeners.Remove(_traceListener);
@@ -110,6 +118,7 @@ namespace Common.Debug
_traceListener.Close(); _traceListener.Close();
_traceListener.Dispose(); _traceListener.Dispose();
_traceListener = null; _traceListener = null;
}
// Close the trace // Close the trace
Trace.Close(); Trace.Close();