本文整理汇总了C#中System.ApplicationException.LogToElmah方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationException.LogToElmah方法的具体用法?C# ApplicationException.LogToElmah怎么用?C# ApplicationException.LogToElmah使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ApplicationException
的用法示例。
在下文中一共展示了ApplicationException.LogToElmah方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMail
/// <summary>
/// Utility to send email.
/// </summary>
/// <param name="toEmailAddress">Email address of the receiver.</param>
/// <param name="mailSubject">Email subject.</param>
/// <param name="mailBody">Email body.</param>
/// <param name="isHtml">Indicates value if the email is in HTML format or plain text.</param>
/// <returns>Returns email send result.</returns>
public static bool SendMail(string toEmailAddress, string mailSubject, string mailBody, bool isHtml = false)
{
var mailSendResult = false;
try
{
var webConfiguration = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
var mailSettingsSectionGroup = (MailSettingsSectionGroup)webConfiguration.GetSectionGroup(BllConstants.WebConfigurationMailSectionGroupNodeName);
if (null != mailSettingsSectionGroup)
{
var fromEmailAddress = mailSettingsSectionGroup.Smtp.Network.UserName;
if (!string.IsNullOrWhiteSpace(fromEmailAddress) && !string.IsNullOrWhiteSpace(toEmailAddress) && !string.IsNullOrWhiteSpace(mailSubject) && !string.IsNullOrWhiteSpace(mailBody))
{
using (var mailMessage = new MailMessage())
{
mailMessage.From = new MailAddress(fromEmailAddress);
toEmailAddress.Split(BllConstants.Semicolon).ToList().ForEach(mailMessage.To.Add);
mailMessage.Subject = mailSubject;
mailMessage.IsBodyHtml = isHtml;
mailMessage.Body = mailBody;
using (var smtpClient = new SmtpClient())
{
var mailConfigurationValid = true;
if (mailMessage.To.Any(mailAddress => mailAddress.Address.Equals(mailMessage.From.Address)))
{
var smtpRelayHost = ConfigurationManager.AppSettings.Get(BllConstants.SmtpRelayHostAppConfigSettingKey);
int smtpRelayPort;
if (!string.IsNullOrEmpty(smtpRelayHost) && int.TryParse(ConfigurationManager.AppSettings.Get(BllConstants.SmtpRelayPortAppConfigSettingKey), out smtpRelayPort))
{
smtpClient.Host = smtpRelayHost;
smtpClient.Port = smtpRelayPort;
smtpClient.EnableSsl = bool.Parse(ConfigurationManager.AppSettings.Get(BllConstants.SmtpRelayEnableSslAppConfigSettingKey));
}
else
{
var applicationException = new ApplicationException(BllConstants.MailRelaySettingsNotFound);
applicationException.LogToElmah();
mailConfigurationValid = false;
}
}
if (mailConfigurationValid)
{
smtpClient.Send(mailMessage);
mailSendResult = true;
}
}
}
}
}
else
{
var applicationExcpetion = new ApplicationException(BllConstants.MailSettingsGroupNotFound);
applicationExcpetion.LogToElmah();
}
}
catch (ArgumentException argumentException)
{
argumentException.LogToElmah();
}
catch (FormatException formatException)
{
formatException.LogToElmah();
}
catch (InvalidOperationException invalidOperationException)
{
invalidOperationException.LogToElmah();
}
catch (SmtpFailedRecipientsException smtpFailedRecipientsException)
{
smtpFailedRecipientsException.LogToElmah();
}
catch (SmtpException smtpException)
{
smtpException.LogToElmah();
}
return mailSendResult;
}