警报在Azure的辅助角色例外 [英] Alerts for exceptions in an Azure worker role

本文介绍了警报在Azure的辅助角色例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法来发送警报或通知,并在Azure管理门户,如果一个工人的作用抛出异常或出现错误?

Is there an easy way to send an alert or notification in the Azure Management portal if a worker role throws an exception or has an error?

我使用Azure的2.5

I am using Azure 2.5

我已经跟踪和诊断全部设立并可以查看在Visual Studio中的服务器资源管理器的日志,但是反正有例如,如果和错误信息出现在日志设置警报。

I have tracing and diagnostics all set up and can view the logs in the server explorer of Visual studio, but is there anyway to set an alert if for example and error message appears in the logs.

我知道你可以设置警报在管理门户监测指标有一个简单的方法来增加对错误和异常指标?

I know you can set up alerts for monitoring metrics in the Management portal is there an easy way to add metrics for errors and exceptions?

还是要想办法让C#的异常code创建在Azure管理门户网站通知或提醒?

Or someway to get C# exception code to create notifications or alerts in the Azure Management portal?

推荐答案

我使用SendGrid通过Azure中发送邮件,因为它是免费的。这里是我会做类似如下:

I use SendGrid for sending emails through Azure because it's free. Here is what I would do something like below:

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);
}

请注意,我存储我的学分在globalvariables类叫做ServerGlobalVariables。另外,我把我的邮件格式为HTML,但是你没有做到这一点。

Please note that I store my credits in a globalvariables class called ServerGlobalVariables. Also, I send my emails formatted as HTML, but you don't have to do that.

让我知道如果您有任何疑问。
〜干杯

Let me know if you have any questions. ~Cheers

这篇关于警报在Azure的辅助角色例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆