private void PushLogToSNS(string snsSubject, string log)
{
if (string.IsNullOrEmpty(Settings.ResultsTopic))
return;
try
{
if (log.Length > snsMaxMessageSize)
{
WriteInfo("Log too long for SNS, truncating...");
var tooLongPrefix = string.Format(logTooLongMessage, snsMaxMessageSizeKb);
var maxCharacters = snsMaxMessageSize - (tooLongPrefix.Length + truncationSuffix.Length);
log =
tooLongPrefix +
log.Substring(0, maxCharacters) +
truncationSuffix;
}
WriteInfo("Pushing log to SNS...");
using (var sns = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(Credentials, RegionEndpoint))
{
sns.PublishAsync(new PublishRequest
{
TopicArn = Settings.ResultsTopic,
Subject = snsSubject,
Message = log
}).Wait();
}
}
catch(Exception e)
{
WriteError("Error pushing logs to SNS: {0}", e);
}
}