Audit Trail Generator Sample
This sample demonstrates how to generate the CME audit trail files for iLink3 log files.
It has the following arguments:
LogFileToAnalyse
- The path to the summary log file used as a source file for audit trail data.OutputFieldDelimiter
- The delimiter between fields in the resulting audit file (optional, the comma is used by default).CMETradeDayStartTimeUtc
- The CME trade day start time in UTC (optional,9:45 UTC
is used by default).hasSofh
-Y
if messages in log contains SOF header (optional,N
used by default)
Usage example:
dotnet OnixS.Cme.ILink3.AuditTrailGenerator.dll LogFileToAnalyse.summary ; 9:45
Results:
LogFileToAnalyse.csv
file;AuditTrailGeneratorLog.txt
file.
NOTE: The format of the summary log file and audit trail requirements for CME iLink 3 differs from the CME iLink 2. Therefore, this tool can generate audit trail files only for the logs created for iLink 3.
Source code
using System;
using System.IO;
using OnixS.Cme.ILink3;
namespace AuditTrailGeneratorSample
{
public class AuditTrailGeneratorSample
{
static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static int Main(string[] args)
{
try
{
if (1 != args.Length && 2 != args.Length && 3 != args.Length && 4 != args.Length)
{
Console.WriteLine("Usage: [LogFileToAnalyse.summary/Logs folder path] (OutputFieldDelimiter) (CMETradeDayStartTimeUtc)\n\t" +
"where CMEStartTradeDayTimeUtc - CME trade day start time in UTC");
return 1;
}
bool hasSofh = false;
string path = args[0];
string outputFieldDelimiter = args.Length > 1 ? args[1] : ",";
// Default time is 9:45 UTC
int hour = 9;
int minute = 45;
if (args.Length >= 3)
{
string time = args[2];
string[] parts = time.Split(":", 2);
hour = int.Parse(parts[0]);
minute = int.Parse(parts[1]);
}
if (args.Length == 4)
{
hasSofh = args[3].ToLower() == "y";
}
DateTime cmeTradeDayStartTimeUtc = new(1970, 1, 1, hour, minute, 0);
var generator = new AuditTrailGenerator(outputFieldDelimiter, @"ilinkbinary.xml", cmeTradeDayStartTimeUtc, @"csv")
{
DateTimeFormat = @"yyyyMMdd-HH:mm:ss.fff",
LicenseStoragePath = "../../../../../license|../../../../license|."
};
//GTD/GTC order trails may exist in multiple files, so for OrderFlowID generation all history must be processed.
if (Directory.Exists(path))
{
var fileEntries = Directory.GetFiles(path, "*.summary");
foreach (string fileName in fileEntries)
{
generator.Generate(fileName);
Console.WriteLine($"Audit trail file for {fileName} generated successfully.");
logger.Info($"Audit trail file for {fileName} generated successfully.");
}
}
else if (File.Exists(path))
{
generator.Generate(path);
Console.WriteLine($"Audit trail file for {path} generated successfully.");
logger.Info($"Audit trail file for {path} generated successfully.");
}
else
{
Console.WriteLine("{0} is not a valid file or directory.", path);
}
}
catch (Exception ex)
{
Console.WriteLine("EXCEPTION: " + ex);
logger.Error("Exception: " + ex.ToString());
Console.WriteLine("Press Enter to exit...");
Console.ReadLine();
return 2;
}
finally
{
NLog.LogManager.Shutdown();
}
return 0;
}
}
}