// Hook: any // Append a one-line CSV entry every time a hook fires during a job. // // Useful for understanding when each hook executes and how many times. The // per-job state helpers (GetValue/SetValue) hold a counter that is shared // across every hook in the same job, so each entry shows the running total. using System.IO; var auditFile = @"c:\Data\script runner logs\reportworq_event_audit.csv"; Directory.CreateDirectory(Path.GetDirectoryName(auditFile)); if (!File.Exists(auditFile)) File.WriteAllText(auditFile, "Timestamp,JobName,HookName,CallCount\n"); // Bump a counter that's shared across every hook in this job var callCount = GetValue("EventAuditCount", 0) + 1; SetValue("EventAuditCount", callCount); AppendLineWithRetry(auditFile, $"{DateTime.UtcNow:O},\"{JobName}\",\"{HookName}\",{callCount}" ); Logger.LogInformation($"Audit event #{callCount} written to '{auditFile}'.");