I am initializing my Azure Diagnostics inside onStart of my Web Role, and have it scheduled to transfer logs every 5 minutes. But when the auto-scale shuts down one my roles we are loosing the logs since the last transfer. What can I do in onStop to prevent this from happening? Is there a way to force the log transfer and prevent onStop from finishing until it's done? Thanks!
2 Answers
Just have your log transfer in the onStop method. Or alternatively, if that's done in a thread, use a flag and a loop in the onStop method to sleep until the flag is set.
SaveLogAsync();
while(!saved)
{
Thread.Sleep(100);
}
There is still a max amount of time the onStop method will run for before it's forced to shut down. I think it's 5 minutes.

- 5,965
- 2
- 40
- 77
-
Yes thanks, but how do i force the logs to be transfered in onStop? I looked for documentation and found nothing so far, thus i am here :) – enlightenedOne Feb 06 '14 at 00:49
To transfer diagnostics data when role is shutting down, you would need to perform an operation called On-Demand Transfer
. This will start transferring the data stored in buffer to diagnostics storage account. You may find this link helpful in performing On-Demand Transfer: http://msdn.microsoft.com/en-us/library/windowsazure/gg433075.aspx.
And David is correct. You get about 5 minutes to perform this operation. See this link for more details: http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx. To handle OnStop event gracefully, you may find this blog post useful: http://blogs.msdn.com/b/windowsazure/archive/2013/01/14/the-right-way-to-handle-azure-onstop-events.aspx.

- 128,066
- 12
- 206
- 241