Not sure why I went off on a tnagent looking at the RetrieveMultiple message. The Retrieve message was what I wanted.
try
{
string[] operationsToAudit = new string[]{"Retrieve", "RetrieveMultiple"};
if (context.Depth == 1 && context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference && operationsToAudit.Contains(context.MessageName) && context.PrimaryEntityName.StartsWith("xcor_"))
{
EntityReference TargetReference = (EntityReference)context.InputParameters["Target"];
Entity entity = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
Entity audit = new Entity("xcor_audit");
audit["xcor_operation"] = context.MessageName;
audit["xcor_entitytype"] = context.PrimaryEntityName;
audit["xcor_entityreferenceguid"] = context.PrimaryEntityId.ToString();
service.Create(audit);
}
}
It all works fine now.