如果员工角色抛出异常或出现错误,是否有一种简单的方式在Azure Management门户中发送警报或通知?
我使用Azure 2.5
我已经设置了所有跟踪和诊断信息,并且可以在Visual的服务器资源管理器中查看日志,但是如果例如日志中出现错误消息,是否仍然需要设置警报。
我知道您可以在Management中设置监视度量的警报,是否有一种简单的方法可以添加错误和异常的度量标准?
或者以某种方式获取C#异常代码,以便在Azure管理门户中创建通知或警报?
发布于 2015-04-30 21:55:42
我使用SendGrid通过Azure发送电子邮件,因为它是免费的。以下是我要做的事情:
try
{
//....
}
catch(Exception ex)
{
MailMessage mailMsg = new MailMessage() {
//Set your properties here
};
// Add the alternate body to the message.
mailMsg.AlternateViews.Add(
AlternateView.CreateAlternateViewFromString(Body
, new System.Net.Mime.ContentType("text/html")));
SmtpClient smtpClient = new SmtpClient(
ServerGlobalVariables.SmtpServerHost
, Convert.ToInt32(587));
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(
ServerGlobalVariables.SmtpServerUserName
, ServerGlobalVariables.SmtpServerPassword);
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
}请注意,我将我的学分存储在一个名为ServerGlobalVariables的全局变量类中。此外,我发送的电子邮件格式为HTML,但你不必这样做。
https://stackoverflow.com/questions/29975871
复制相似问题