using System.Diagnostics;
using System.IO;
using System.Threading;

namespace QC.TestResultsLite;

public class TraceWriter
{
	private static TextWriterTraceListener myListener;

	private static bool enabled;

	public static Mutex mutMessage;

	public static bool Enabled
	{
		get
		{
			return enabled;
		}
		set
		{
			enabled = value;
		}
	}

	static TraceWriter()
	{
		enabled = false;
		mutMessage = new Mutex(initiallyOwned: false);
		try
		{
			FileStream stream = new FileStream("C:\\Qualcomm\\QSPR\\TraceLogs\\UltraResults.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
			myListener = new TextWriterTraceListener(stream);
			Trace.Listeners.Add(myListener);
		}
		catch
		{
		}
	}

	public static void WriteLine(string traceLog, string category)
	{
		mutMessage.WaitOne();
		try
		{
			if (Enabled)
			{
				myListener.WriteLine(traceLog, category);
				myListener.Flush();
			}
		}
		catch
		{
		}
		mutMessage.ReleaseMutex();
	}

	public static void WriteLine(string traceLog)
	{
		mutMessage.WaitOne();
		try
		{
			if (Enabled)
			{
				myListener.WriteLine(traceLog, "Trace");
				myListener.Flush();
			}
		}
		catch
		{
		}
		mutMessage.ReleaseMutex();
	}
}
