// Hook: AfterSend // Append a one-line audit entry to a shared summary CSV. // // Operations teams get a machine-readable trail of every job result without // needing access to the ReportWORQ job history database. // // Note: File.AppendAllLines is not thread-safe for concurrent writes. In // high-concurrency deployments, use a mutex/lock or write to a database/queue. using System.IO; var auditFile = @"c:\Data\script runner logs\reportworq_audit.csv"; var status = JobResult.Success ? "SUCCESS" : "FAILURE"; var errorSummary = JobResult.Errors.Any() ? string.Join("; ", JobResult.Errors.Take(3)) : ""; // Escape any embedded double quotes so the CSV stays well-formed var safeErrors = errorSummary.Replace("\"", "\"\""); var elapsed = JobResult.Elapsed.TotalSeconds; var line = $"{DateTime.UtcNow:O},\"{JobName}\",\"{OutputName}\",{status},\"{safeErrors}\",{elapsed:F1}s"; File.AppendAllLines(auditFile, new[] { line }); Logger.LogInformation($"Audit entry written to '{auditFile}'.");