David Fugate 7396642963 This commit includes Microsoft's initial contributions to Test262:
- external\contributions\: test contributions to Test262 from external entities such as Microsoft and Google.
                           This directory consists of the external tests without any modifications
- test\harness\:  test harness used to run Test262 tests.  Presently web-based
- test\suite\:    suite of vendor-neutral ECMAScript test cases conforming to the ES5 spec
- tools\:         among other things this includes a set of tools used to convert various external test
                  contributions to a format the Test262 test harness can consume
- website\:       an archived copy of the http://test262.ecmascript.org website
2010-10-18 20:50:07 -07:00

94 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
namespace Microsoft.Sputnik.Interop.ParserEngine
{
public class Logger
{
private static string logFileDir = string.Empty;
private StreamWriter writer;
private static Logger logger;
private Logger()
{
logFileDir = ConfigurationManager.AppSettings[ResourceClass.LogFileDirectorySettingKey].ToString();
string filename = Path.Combine(logFileDir, string.Concat(DateTime.Now.ToString("MM-dd-yyyy"), ".log"));
writer = File.CreateText(filename);
}
private static Logger GetLoggerInstance()
{
if (logger == null)
{
logger = new Logger();
}
return logger;
}
public static void WriteToLog(string logText)
{
Logger logger = GetLoggerInstance();
logger.Write(logText);
}
private void Write(string logText)
{
try
{
writer.WriteLine(logText);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
private void Write(string format, params string[] args)
{
try
{
writer.WriteLine(format, args);
}
catch (FormatException ex)
{
Console.WriteLine(ex.Message);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// Method to write execution progress information to the log file
/// </summary>
/// <param name="format">The format.</param>
/// <param name="args">The args.</param>
public static void WriteToLog(string format, params string[] args)
{
Logger logger = GetLoggerInstance();
logger.Write(format, args);
}
public static void Dispose()
{
Logger logger = GetLoggerInstance();
logger.DisposeWriter();
}
private void DisposeWriter()
{
if (writer != null)
{
writer.Dispose();
}
}
}
}