简体   繁体   中英

How do I log and retrieve Azure Worker role exceptions?

I have a free account with Azure (90 day trial) and I'm finding that my worker role is erroring out. I don't have any of the monitoring features enabled because I believe they cost money.

Is there any way for me to log the errors and store them somewhere where I can retrieve them without having to upgrade my account to a paid account?

To take a look at ( Windows Azure Diagnostics ) which will allow you to collect diagnostics data (trace logs, event logs, perf. counters etc.) for your worker role. Depending on the configuration, this diagnostics data can be persisted into Windows Azure Table storage. You can view the diagnostics data using any storage explorer.

What I've found myself that is was quite time consuming to implement the Azure Diagnostics, and the best way so far, was to launch the Azure Emulator on my machine, and see what error's it shows.

What You do, is simple set up Your Azure project as startup and run it. Or right click on the Azure project and select : Debug -> Start New Instance

You can attach an event for unhandled exceptions in worker role OnStart() method.

    public override bool OnStart()
    {
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

        bool result = base.OnStart();

        Trace.TraceInformation("ReceiverRole has been started");

        return result;
    }


    private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        Trace.TraceError("Unhandled exception in worker role: {0}", e.ExceptionObject);
    }

The skinny cheap way is to add to the role error handler that sends the exception contents with stack to an StorageAccount table. You can use a cloud storage browser to view the table contents to see the details of the exception. This could be matured over time to have a nice 'in house' app that downloads the table contents into SS and create a smart client that can browse the errors.

I have this system implemented in a way that I can set verbosity and address the timestamps via UTC. The logging is done in a separate worker role so that the 'production' roles post to a queue which is alot faster for the failing role to deal with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM