2023-07-18 07:02:41 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace Logging
|
|
|
|
|
{
|
|
|
|
|
public class StatusLog
|
|
|
|
|
{
|
|
|
|
|
private readonly object fileLock = new object();
|
|
|
|
|
private readonly string fullName;
|
|
|
|
|
private readonly string fixtureName;
|
|
|
|
|
|
2023-07-31 09:51:29 +00:00
|
|
|
|
public StatusLog(LogConfig config, DateTime start, string name = "")
|
2023-07-18 07:02:41 +00:00
|
|
|
|
{
|
2023-07-18 08:39:27 +00:00
|
|
|
|
fullName = NameUtils.GetFixtureFullName(config, start, name) + "_STATUS.log";
|
2023-07-18 07:02:41 +00:00
|
|
|
|
fixtureName = NameUtils.GetRawFixtureName();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 11:58:50 +00:00
|
|
|
|
public void ConcludeTest(string resultStatus, string testDuration, ApplicationIds applicationIds)
|
2023-07-18 07:02:41 +00:00
|
|
|
|
{
|
|
|
|
|
Write(new StatusLogJson
|
|
|
|
|
{
|
2023-07-18 12:26:21 +00:00
|
|
|
|
@timestamp = DateTime.UtcNow.ToString("o"),
|
2023-07-18 09:04:14 +00:00
|
|
|
|
runid = NameUtils.GetRunId(),
|
2023-07-18 07:47:44 +00:00
|
|
|
|
status = resultStatus,
|
2023-07-18 09:04:14 +00:00
|
|
|
|
testid = NameUtils.GetTestId(),
|
2023-08-10 11:58:50 +00:00
|
|
|
|
codexid = applicationIds.CodexId,
|
|
|
|
|
gethid = applicationIds.GethId,
|
|
|
|
|
prometheusid = applicationIds.PrometheusId,
|
|
|
|
|
codexcontractsid = applicationIds.CodexContractsId,
|
2023-08-13 08:07:47 +00:00
|
|
|
|
grafanaid = applicationIds.GrafanaId,
|
2023-07-18 11:18:26 +00:00
|
|
|
|
category = NameUtils.GetCategoryName(),
|
2023-07-18 07:02:41 +00:00
|
|
|
|
fixturename = fixtureName,
|
2023-07-21 07:20:28 +00:00
|
|
|
|
testname = NameUtils.GetTestMethodName(),
|
|
|
|
|
testduration = testDuration
|
2023-07-18 07:02:41 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Write(StatusLogJson json)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (fileLock)
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllLines(fullName, new[] { JsonConvert.SerializeObject(json) });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Unable to write to status log: " + ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StatusLogJson
|
|
|
|
|
{
|
2023-07-18 12:26:21 +00:00
|
|
|
|
public string @timestamp { get; set; } = string.Empty;
|
2023-07-18 07:02:41 +00:00
|
|
|
|
public string runid { get; set; } = string.Empty;
|
|
|
|
|
public string status { get; set; } = string.Empty;
|
|
|
|
|
public string testid { get; set; } = string.Empty;
|
|
|
|
|
public string codexid { get; set; } = string.Empty;
|
2023-08-10 11:58:50 +00:00
|
|
|
|
public string gethid { get; set; } = string.Empty;
|
|
|
|
|
public string prometheusid { get; set; } = string.Empty;
|
|
|
|
|
public string codexcontractsid { get; set; } = string.Empty;
|
2023-08-13 08:07:47 +00:00
|
|
|
|
public string grafanaid { get; set; } = string.Empty;
|
2023-07-18 11:18:26 +00:00
|
|
|
|
public string category { get; set; } = string.Empty;
|
2023-07-18 07:02:41 +00:00
|
|
|
|
public string fixturename { get; set; } = string.Empty;
|
|
|
|
|
public string testname { get; set; } = string.Empty;
|
2023-07-21 07:20:28 +00:00
|
|
|
|
public string testduration { get; set;} = string.Empty;
|
2023-07-18 07:02:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|