none
Unhandled exception logging in worker role

    Question

  • Hi

    I'm having a bit of trouble capturing the text of unhandled exceptions in my worker roles. Has anyone got any sample code for doing this?

    I know I could do a try..catch...

    Cheers

    David

    Sunday, August 22, 2010 6:19 PM

Answers

  • Hi David,

    You could write just one try...catch construct in the Run() method of the worker role. This way you can catch any exception thrown in your implementation. I don't see why this is too much effort for a prototype.

    Otherwise you should see some error information in the Dev Fabric Diagnostics monitor.


    Regards, Patriek
    • Marked as answer by DavidM51 Monday, August 23, 2010 10:13 AM
    Monday, August 23, 2010 9:50 AM

All replies

  • Hi David,

    Generally, to log the error message in cloud app, you need config the cloud diagnostic, then use try...catch to get the exception and write to log. For how to use cloud loging and tracing, please refer to this article

    http://msdn.microsoft.com/en-us/magazine/ff714589.aspx

    Thanks,


    Mog Liang
    Monday, August 23, 2010 5:30 AM
  • Hi Mog Liang

    Thanks for the reply. Is there any way I can do this without using try..catch? When I'm prototyping a new app, it's annoying to have to spend ages writing error handling code when I'm still in the testing phase.

    I've noticed that for a web role these exceptions are nicely presented in the application log, but there seems to be no equivalent for a worker role. Is that correct?

    Cheers

    David

    Monday, August 23, 2010 7:24 AM
  • Thanks for the reply. Is there any way I can do this without using try..catch? When I'm prototyping a new app, it's annoying to have to spend ages writing error handling code when I'm still in the testing phase.

    If you are using service bus architecture, then you can employ something similar to BlobExceptionLogger from Lokad.CQRS for Azure that will handle all command failures, logging exceptions into the blob:

    PingPongCommand
    
     Topic     : PingPongCommand
     ContractName  : PingPongCommand
     Sender     : http://127.0.0.1:10001/devstoreaccount1/sample-04
     Identity    : d5743fde-28cb-4ba7-a6ca-9ddb0083a7a9
     CreatedUtc   : 08/23/2010 07:59:20
    
    
    Content
    =======
    PingPongCommand
    {
     "Ball": 5,
     "Game": "justo"
    }
    
    Exception Detail
    ================
    Type:    Sample_04.Worker.BounceFailedException
    Message:   Bouncing failed for: Ping #5 in game 'justo'.
    Source:   Lokad.Cqrs.Stack
    Recorded:  2010-08-23-07-59-20-8778
    TargetSite: Void InvokeConsume(System.Object, System.Object, System.String)
    StackTrace:
      at Sample_04.Worker.PingPongHandler.Consume(PingPongCommand message) in D:\Lokad.Cqrs\Samples\Sample_04\Sample_04.Worker\Domain.cs:line 74
      at Lokad.Cqrs.Domain.MessageReflectionUtil.InvokeConsume(Object messageHandler, Object messageInstance, String methodName)
      at Lokad.Cqrs.Domain.MessageDirectory.InvokeConsume(Object consumer, Object message)
      at Lokad.Cqrs.Consume.DispatchesSingleMessage.DispatchMessage(UnpackedMessage message)
      at Lokad.Cqrs.Consume.ConsumingProcess.TransportOnMessageRecieved(UnpackedMessage arg)
      at System.Func`2.Invoke(T arg)
      at Lokad.Cqrs.Transport.AzureQueueTransport.b__b(UnpackedMessage m)
      at Lokad.Cqrs.Transport.AzureQueueTransport.ProcessSingleMessage(UnpackedMessage message, Func`2 messageHandlers)
      at Lokad.Cqrs.Transport.AzureQueueTransport.Process(IReadMessageQueue queue, UnpackedMessage message)
    

    Detais

    Alternatively, you can use something like Xmpp protocol to send all failures and log messages to the jabber window in real-time.

     


    http://abdullin.com
    Monday, August 23, 2010 8:02 AM
  • Hi Rinat

    This is just a plain vanilla worker role.

    Are you saying that it's not possible to get the exception directly from Azure?

    Cheers

    David

    Monday, August 23, 2010 9:38 AM
  • Hi David,

    You could write just one try...catch construct in the Run() method of the worker role. This way you can catch any exception thrown in your implementation. I don't see why this is too much effort for a prototype.

    Otherwise you should see some error information in the Dev Fabric Diagnostics monitor.


    Regards, Patriek
    • Marked as answer by DavidM51 Monday, August 23, 2010 10:13 AM
    Monday, August 23, 2010 9:50 AM
  • David,

    if you are running a simple worker role, then that's probably a single thread. You can just put a single try-catch in the Run() and print exception details to the BLOB.


    http://abdullin.com
    Thursday, August 26, 2010 4:02 AM