Azure, C#

Azure Webjob not starting – Status Pending Restart

Recently I have been working with WebJobs and one common issue while deploying these is getting a Pending Restart status on the Azure Portal.

Pending Restart basically means there was an error/exception while Azure tried to run your Job.

First of all check your Webjob logs and see the exception being thrown:

Now go back and check for the code you have written in your WebJob and see if something needs to be fixed.


Issue for me was related to configuration. There are 3 important configuration settings you need in your webjob config file:

  1. ServiceBus Connectionstring (Connectionstribf to your ASB namespace)
  2. AzureWebJobsDashboard (This would come from Azure storage A/C you want to use to store the logs from the job)
  3. AzureWebJobsStorage (same as above)


Final words

Webjobs are a great way to do background processing/ supporting async operations/ reading or writing to Queues and should be leveraged whenever there’s a use case for them.


Azure, C#, Logging

How to log from Azure Web Jobs

The simplest way to enable logging in a Web Job that runs Continuously is by first enabling Application Logs from the Azure Portal and using Console.Write() in the actual WebJob file.


Here’s the code for the Function class which holds a method “ProcessQueueMessage”, gets executed whenever there’s a new message in the queue:

Webjob logging code C#


To enable logging, go to the portal => Web Job = > Diagnostics  logs=> Turn on application logging (Filesystem (You can also use a Blog/Table storage which is more robust)):


We can see the logs from the Log section in the webJob from the portal:

Webjob logs


Also there’s a way to see logs as a stream(You aren’t seeing any log messages on the stream as no activity is going on but trust me it works :-))


Final Words

The only downside with using FileSystem for logging is that it automatically shuts down logging after few hours. To enable logging permanently, use Blog/Table storage.