Windows Azure Blog
Microsoft Cloud Computing Platform
Microsoft Store
  • Home
  • Windows Azure Team Blog
You are here : Windows Azure Blog » Stack Overflow Azure » Azure Worker role error handling

Azure Worker role error handling

Posted On Tuesday, April 24, 2012 By rss. Under Stack Overflow Azure    

working with worker roles is a little bit tricky if something goes wrong. I have exception occuring in my worker role, which forces role to quit and restart. I decided to implemet azure diagnostics solution to log what is going on. It works, when i try to write message to trace, but i am unable to catch exceptions and wlog them. I surround my wode with try catch and try to write exception contents to trace. Is this right approach? And why does it not work? Is there any better way to log exceptions in worker roles? Thank you. My code is:

public class WorkerRole : RoleEntryPoint
{
private const int WAIT_INTERVAL_SECONDS = 15;

    public override void Run()
    {
        Trace.WriteLine("$projectname$ entry point called", "Information");

        while (true)
        {

            try
            {
                string id = MainWCFRole.Storage.TrackProcessingQueueDAO.retrieveMsgContents();
                if ((id != null) && (!id.Equals("")))
                {
                    var points = MainWCFRole.Storage.TrackRawDataDAO.retrieve(id);

                    Processor.process(id, points);
                }
                else
                {
                    Thread.Sleep(WAIT_INTERVAL_SECONDS * 1000);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("Something went wrong");
                Trace.TraceError(ex.ToString());
                throw ex;
            }


        }
    }

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections 
        ServicePointManager.DefaultConnectionLimit = 12;

        DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
        dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
        dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
        dmc.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
        dmc.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);


        DiagnosticMonitor.Start("StorageConnectionString", dmc);

        Trace.TraceInformation("Starting Worker Role TrackProcessor");

        return base.OnStart();
    }

}

Processor.process(id, points) is method which throws exception. More precisely, it is when i try to call SQL azure query. I know that diagnostics works, because when role starts, it calls Trace.TraceInformation(“Starting Worker Role TrackProcessor”); and it is visible in the table storage as mesage. Then over time more messages occur, as role encounters exception and is forced to restart. However, no error messages in log.

http://stackoverflow.com/questions/10303377/azure-worker-role-error-handling

Share this:

  • Print
  • Email
  • Facebook
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
« Azure Role Enviroment not initialising
Azure web application how to show error message »
  • Categories
    • AppFabric Team Blog (13)
    • Channel 9 (440)
    • cloud development blog (42)
    • Cloudy in Seattle (10)
    • Convective (12)
    • Matias Woloski (15)
    • Nick Harris .NET – Enterprise Development with Azure, ASP .NET MVC and Windows Phone 7 (50)
    • OakLeaf Systems (427)
    • Scott Hanselman's Blog (31)
    • ScottGu (18)
    • SQL Azure Team Blog (29)
    • Stack Overflow Azure (7545)
    • Uncategorized (16)
    • Wade Wegner (19)
    • Windows Azure Developer Tools Team (25)
    • Windows Azure Marketplace DataMarket Blog (26)
    • Windows Azure Storage Team Blog (63)
    • Windows Azure Team Blog (563)
    • Windows Phone Developer Blog (56)
    • Zane Adam's blog (22)
  • Translator
    English flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroatian flagDanish flagFinnish flagHindi flagPolish flagRomanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flagAlbanian flagEstonian flagGalician flagMaltese flagThai flagTurkish flagHungarian flagBelarus flagIrish flagIcelandic flagMacedonian flagMalay flagPersian flag
  • Recent Posts
    • Windows Azure Add-AzureVhd Powershell command
    • Accessing WCF in Azure by $.ajax yields "NETWORK_ERR: XMLHttpRequest Exception 101"
    • Azure Cache throws exception
    • CSS Transition effects missing after uploading to Azure
    • Is it possible to update configuration settings programmatically?
  • Advertisements

  • RSS

    Windows Azure Blog

  • Twitter
  • Categories
    AppFabric Team Blog Channel 9 cloud development blog Cloudy in Seattle Convective Matias Woloski Nick Harris .NET - Enterprise Development with Azure, ASP .NET MVC and Windows Phone 7 OakLeaf Systems ScottGu Scott Hanselman's Blog SQL Azure Team Blog Stack Overflow Azure Uncategorized Wade Wegner Windows Azure Developer Tools Team Windows Azure Marketplace DataMarket Blog Windows Azure Storage Team Blog Windows Azure Team Blog Windows Phone Developer Blog Zane Adam's blog
Mocell WordPress Theme By MagPress.com
Thanks to Cat Lovers | Meet Locals | Florida Chat
Copyright © 2013. All Rights Reserved.
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.