2023-09-13 14:06:05 +00:00
|
|
|
|
using Logging;
|
|
|
|
|
using Newtonsoft.Json;
|
2023-11-14 11:56:47 +00:00
|
|
|
|
using System.Globalization;
|
2023-09-13 14:06:05 +00:00
|
|
|
|
|
2023-09-20 08:51:47 +00:00
|
|
|
|
namespace DistTestCore.Logs
|
2023-09-13 14:06:05 +00:00
|
|
|
|
{
|
|
|
|
|
public class StatusLog
|
|
|
|
|
{
|
|
|
|
|
private readonly object fileLock = new object();
|
|
|
|
|
private readonly string fullName;
|
|
|
|
|
private readonly string fixtureName;
|
2023-11-10 14:28:53 +00:00
|
|
|
|
private readonly string testType;
|
2023-09-13 14:06:05 +00:00
|
|
|
|
|
2023-11-10 14:28:53 +00:00
|
|
|
|
public StatusLog(LogConfig config, DateTime start, string testType, string name = "")
|
2023-09-13 14:06:05 +00:00
|
|
|
|
{
|
|
|
|
|
fullName = NameUtils.GetFixtureFullName(config, start, name) + "_STATUS.log";
|
|
|
|
|
fixtureName = NameUtils.GetRawFixtureName();
|
2023-11-10 14:28:53 +00:00
|
|
|
|
this.testType = testType;
|
2023-09-13 14:06:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 10:35:45 +00:00
|
|
|
|
public void ConcludeTest(string resultStatus, TimeSpan testDuration, Dictionary<string, string> data)
|
|
|
|
|
{
|
2023-11-14 11:56:47 +00:00
|
|
|
|
ConcludeTest(resultStatus, testDuration.TotalSeconds.ToString(CultureInfo.InvariantCulture), data);
|
2023-11-09 10:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 14:06:05 +00:00
|
|
|
|
public void ConcludeTest(string resultStatus, string testDuration, Dictionary<string, string> data)
|
|
|
|
|
{
|
|
|
|
|
data.Add("timestamp", DateTime.UtcNow.ToString("o"));
|
|
|
|
|
data.Add("runid", NameUtils.GetRunId());
|
|
|
|
|
data.Add("status", resultStatus);
|
|
|
|
|
data.Add("category", NameUtils.GetCategoryName());
|
|
|
|
|
data.Add("fixturename", fixtureName);
|
2023-11-09 10:35:45 +00:00
|
|
|
|
if (!data.ContainsKey("testname")) data.Add("testname", NameUtils.GetTestMethodName());
|
2023-11-10 14:28:53 +00:00
|
|
|
|
data.Add("testid", NameUtils.GetTestId());
|
|
|
|
|
data.Add("testtype", testType);
|
2023-09-13 14:06:05 +00:00
|
|
|
|
data.Add("testduration", testDuration);
|
2023-11-13 10:56:02 +00:00
|
|
|
|
data.Add("testframeworkrevision", GitInfo.GetStatus());
|
2023-09-13 14:06:05 +00:00
|
|
|
|
Write(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Write(Dictionary<string, string> data)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (fileLock)
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllLines(fullName, new[] { JsonConvert.SerializeObject(data) });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Unable to write to status log: " + ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|