We are implementing an Event System to record the publish transaction information to a log file and a custom database. When a single page is published all the states it goes through are being captured in the log file; however, when multiple pages are published not all transactions are being captured.
We are subscribing to the PublishTransaction event.
EventSystem.Subscribe<PublishTransaction, SaveEventArgs>(HandleForPublishTransactionSaved, EventPhases.TransactionCommitted);
The event handler captures the transaction details and logs that to a file.
public void HandleForPublishTransactionSaved(PublishTransaction transaction, SaveEventArgs args, EventPhases phase)
{
foreach (IdentifiableObject id in transaction.Items)
{
// publishTransaction = transaction.Title + transaction.State.ToString() + ..
if (!File.Exists(filePath))
{
using (StreamWriter sw = File.CreateText(filePath))
{
sw.WriteLine(publishTransaction.ToString());
}
}
using (StreamWriter sw = File.AppendText(filePath))
{
sw.WriteLine(publishTransaction.ToString());
}
}
}
The log file when a single page is published:
tcm:0-3582408-66560, Page title, tcm:194-35857-64, WaitingForPublish, 7/18/2017 11:00:12 PM
tcm:0-3582408-66560, Page title, tcm:194-35857-64, InProgress, 7/18/2017 11:00:14 PM
tcm:0-3582408-66560, Page title, tcm:194-35857-64, Resolving, 7/18/2017 11:00:14 PM
tcm:0-3582408-66560, Page title, tcm:194-35857-64, Rendering, 7/18/2017 11:00:14 PM
tcm:0-3582408-66560, Page title, tcm:194-35857-64, Failed, 7/18/2017 11:00:34 PM
tcm:0-3582408-66560, Page title, tcm:194-35857-64, Failed, 7/18/2017 11:00:34 PM
When more than one page are published the logs were not consistent. Several states didn't get recorded for one or more pages. We also tried to log just to the Event Viewer and the results were similar. Tried adding locks to the event handler and that didn't help either.
Is there a way I could prevent this random behavior? Any help would be greatly appreciated!