How do I write to the logs in Azure WebJobs from a C# console app?

Regarding logs:

For continuous WebJobs - Console.Out and Console.Error are routed to the "application logs", they will show up as file, blob or table storage depends on your configuration of the application logs (similar to your Website).

Also the first 100 lines in each invocation will also go to the WebJob log file (to ease debugging pain when the WebJob fails at startup) accessible using the Azure portal (but also saved on your site's file system at data/jobs/continuous/jobName).

For triggered/scheduled WebJobs - Console.Out/Console.Error are routed to the WebJobs specific run log file also accessible using the Azure portal and stored at data/jobs/triggered/jobName/runId.

Console.Out is treated (marked) as INFO and Console.Error as ERROR.

Regarding connection strings:

You can access your connection strings the same as in your website, using the ConfigurationManager class, for WebJobs not written in .NET you can find these connection strings (and app settings) as environment variables (all the same as with your Website).


I was able to get Console.WriteLine() to leave messages in my web job log. The following console runs and leaves log messages.

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            DoStuff();
            Thread.Sleep(10000);
        }
    }

    public static void DoStuff()
    {
        Console.WriteLine("do stuff");
    }
}

This is what my log file shows:

[03/15/2014 04:05:28 > cf6d00: SYS INFO] Run script 'HelloWebJobConsoleApplication.exe' with script host - 'WindowsScriptHost'
[03/15/2014 04:05:28 > cf6d00: SYS INFO] Status changed to Running
[03/15/2014 04:05:28 > cf6d00: INFO] do stuff
[03/15/2014 04:05:38 > cf6d00: INFO] do stuff
[03/15/2014 04:05:48 > cf6d00: INFO] do stuff
[03/15/2014 04:05:58 > cf6d00: INFO] do stuff