/// <inheritdoc /> public virtual async Task <IEnumerable <TEntity> > CreateAsync( IEnumerable <TEntity> items, CancellationToken cancellationToken = default) { AuditScope auditScope = null; IEnumerable <TEntity> created = default; var isServiceException = false; try { auditScope = await AuditScope.CreateAsync($"{EntityName}:Create+", () => created); auditScope.Event.Environment.UserName = UserContext.CurrentUser; auditScope.Event.Target.Type = $"{items.GetType()}"; try { created = await DecoratedService.CreateAsync(items, cancellationToken); } catch { isServiceException = true; auditScope.Discard(); throw; } } catch (Exception e) { if (isServiceException) { throw; } Logger.Warning(e, "Auditing failed for CreateAsync+ of type {Entity}.", EntityName); } finally { if (auditScope != null) { await auditScope.DisposeAsync(); } } return(created); }