34 lines
951 B
C#
34 lines
951 B
C#
using System;
|
|
using System.IO;
|
|
using System.Diagnostics;
|
|
|
|
namespace ASTM_D7896_Tester.Services
|
|
{
|
|
public static class Logger
|
|
{
|
|
private static readonly object _lock = new object();
|
|
private static string _logFilePath = "D7896_Test_Log.txt";
|
|
|
|
public static void Log(string message, bool toConsole = true, bool toFile = true)
|
|
{
|
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
|
string logLine = $"{timestamp} - {message}";
|
|
|
|
if (toConsole)
|
|
Debug.WriteLine(logLine);
|
|
|
|
if (toFile)
|
|
{
|
|
lock (_lock)
|
|
{
|
|
File.AppendAllText(_logFilePath, logLine + Environment.NewLine);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void LogData(string label, double value, string unit = "")
|
|
{
|
|
Log($"{label}: {value:F6} {unit}".Trim());
|
|
}
|
|
}
|
|
} |