I'm testing out Azure Webjobs. I wrote a console application which polls a SQL database for new work and processes it. I'm not using the WebJobs SDK because it only supports Azure Storage.
I upload the job, it runs, and then it fails with a exception that says it wasn't able to connect to the SQL Database instance. I'm wondering what connection string is being used; is it getting the connection string from the Azure Website. The logs give me this:
[03/14/2014 22:24:25 > 512206: SYS INFO] Status changed to Running
[03/14/2014 22:24:40 > 512206: ERR ]
[03/14/2014 22:24:40 > 512206: ERR ] Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I would like to write data to these logs (like what is the connection string that is being used). I tried Console.WriteLine, Debug.WriteLine, Console.Error.WriteLine. None of them show up in the in my WebJob log.
Apparently I could get the data by just raising an exception with the message text showing what I want, but there must be a better way! How do I write SYS INFO lines and ERR lines to the log?
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).