首页 文章

调试Azure Cloud 服务Web角色的最佳方法

提问于
浏览
0

我终于开始阅读有关SOA的内容,并且正在为WCF提供Azure Cloud 服务 . 我觉得特别困难的一件事是调试 . 假设我创建一个服务并将其作为Azure Cloud 服务部署到Web并且有错误,我该如何检查这些错误是什么?我目前有一个接受普通旧POCO的服务,然后将数据添加到两个Azure数据库 . 我的操作 Contract 方法返回一个bool,指示CRUD语句是失败还是传递 . 我一直得到一个假bool,但没有办法踩到代码或使用日志记录方法记录每个代码行 .

public bool SubmitSupportRequest(SupportRequestPacket packet)
    {
        bool status;

        //convert SupportRequestPacket to entities
        var ameeEntity = new AccuDb_Entities.SupportTicket();
        var preferedEntity = new AccuDb_Entities.Support_Requests();
        //ameeEntity will be depreciated soon. Moving all support requests to Accu_Db (second entity)

        ameeEntity.Client = packet.Client;
        ameeEntity.Date = packet.Date;
        ameeEntity.Description = packet.Description;
        ameeEntity.FirstName = !string.IsNullOrEmpty(packet.FirstName) ? packet.FirstName : "None Provided";
        ameeEntity.Ip = !string.IsNullOrEmpty(packet.IP) ? packet.IP : "None Provided";
        ameeEntity.LastName = !string.IsNullOrEmpty(packet.LastName) ? packet.LastName : "None Provided";
        ameeEntity.MachineName = packet.MachineName;
        ameeEntity.ProblemFrequency = packet.ProblemFrequency;
        ameeEntity.TypeOfProblem = packet.TypeOfProblem;

        preferedEntity.Client = packet.Client;
        preferedEntity.Date = packet.Date;
        preferedEntity.Description = packet.Description;
        preferedEntity.FirstName = !string.IsNullOrEmpty(packet.FirstName) ? packet.FirstName : "None Provided";
        preferedEntity.Ip = !string.IsNullOrEmpty(packet.IP) ? packet.IP : "None Provided";
        preferedEntity.LastName = !string.IsNullOrEmpty(packet.LastName) ? packet.LastName : "None Provided";
        preferedEntity.MachineName = packet.MachineName;
        preferedEntity.ProblemFrequency = packet.ProblemFrequency;
        preferedEntity.TypeOfProblem = packet.TypeOfProblem;

        using (var tempContext = new AccuDb_Entities.ameesupporttickets_dbEntities())
        {
            try
            {
                tempContext.SupportTickets.Add(ameeEntity);
                tempContext.SaveChanges();
                status = true;
            }
            catch
            {
                status = false;
                return status;
            }

        }

        using (var context = new AccuDb_Entities.Accu_DbEntities())
        {
            try
            {
                context.Support_Requests.Add(preferedEntity);
                context.SaveChanges();
                status = true;
            }
            catch
            {
                status = false;
            }
        }

        return status;
    }

1 回答

  • 2

    这是一个非常广泛的问题,如果不写一篇很长的文章就很难提出具体的问题 .

    如果您使用的是 Cloud 服务(听起来像是这样),那么您可以配置各种诊断日志记录,并在 Cloud 项目中记录跟踪日志的发送 . 然后,您可以在web.config中配置跟踪侦听器,它将每隔一两分钟将您使用 Trace.Write 等记录的所有内容发送到Azure表存储中,具体取决于您的配置,如下所示:

    <system.diagnostics>
       <trace>
          <listeners>
             <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, 
                Microsoft.WindowsAzure.Diagnostics, 
                Version=2.3.0.0, 
                Culture=neutral, 
                PublicKeyToken=31bf3856ad364e35"
                name="AzureDiagnostics">
                <filter type="" />
             </add>
          </listeners>
       </trace>
    </system.diagnostics>​
    

    然后,您可以直接在表存储中读取这些日志,或使用像Cerebrate这样的工具来获得更漂亮的格式 . 这将使您能够在代码执行时输出尽可能多的信息 .

    需要注意的是,您可以使用不同级别进行操作,因此您可以将消息记录为详细信息,并且可以更改在config中将哪个消息级别传输到表存储;这意味着您可以在调试后将日志记录调用留在代码中,只需将传输级别切换为“信息”或“警告”,以避免在表存储中看到详细消息 .

    如果您还打开了一些诊断监控和站点日志记录,您也可以将各种其他统计信息输入到表存储中 .

    与任何“正常”WCF调试一样,您可以在Web.config中打开许多特定于WCF的转储选项,这将在磁盘上生成跟踪文件 . 然后,您可以在您的 Cloud 服务中使用RDP来检索这些文件(我假设您熟悉WCF,如果没有,请道歉) .

    根据您的Visual Studio版本,您也可以在启用intellitrace的情况下进行部署,然后您可以下载这些文件并在Visual Studio中播放它们 .

    我很抱歉相当模糊,这是一个相当大的主题,你需要花一些时间与它合作才能正确理解 .

    哦,如果你看一下Azure网站,它们就完全不同了(虽然你可以做尾部日志记录更好) .

    顺便说一句,如果您构建一个全新的SOA系统,您可能希望使用Web API来构建RESTful服务而不是使用WCF . 只是在说' :)

相关问题