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.

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s