private void LogExpiryDetails(ExpiryCalculationArgs args, string grainType, string primaryKey) { string message; var grainName = grainType.Trim().EndsWith("Grain", StringComparison.InvariantCultureIgnoreCase) ? grainType : $"{grainType} grain"; switch (args.Expiry.Source) { case ExpiryCalculationArgs.ExpirySources.NoExpiry: message = $"{grainName} with key {primaryKey} has no expiry value set"; break; case ExpiryCalculationArgs.ExpirySources.ConfigFile: message = $"{grainName} with key {primaryKey} has an expiry value of {args.Expiry.Expiry.ToLongString()} provided by config file."; break; case ExpiryCalculationArgs.ExpirySources.Dynamic: message = $"{grainName} with key {primaryKey} has an expiry value of {args.Expiry.Expiry.ToLongString()} provided by dynamic expiry calculator"; break; case ExpiryCalculationArgs.ExpirySources.ErrorValue: var detailedMessage = new StringBuilder(); detailedMessage.AppendLine($"{grainName} with key {primaryKey} has an expiry value of {args.Expiry.Expiry.ToLongString()} which is error fallback value."); detailedMessage.AppendLine($"Grain state: {args.Data}"); detailedMessage.AppendLine($"Exception: {args.CalculationException}"); message = detailedMessage.ToString(); break; default: throw new InvalidEnumArgumentException($"{args.Expiry.Source} is not a valid value for expiry source"); } Logger.Info(message); }
private ExpiryCalculationArgs BuildExpiryCalculationArgs(string grainType, string entityData, string primaryKey) { var expiry = TimeSpan.Zero; var expirySource = ExpiryCalculationArgs.ExpirySources.NoExpiry; if (DocumentExpiries.ContainsKey(grainType)) { expiry = DocumentExpiries[grainType]; expirySource = ExpiryCalculationArgs.ExpirySources.ConfigFile; } var args = new ExpiryCalculationArgs(grainType, entityData, new ExpiryCalculationArgs.ExpirySourceAndValue { Source = expirySource, Expiry = expiry }, primaryKey); return(args); }