How to write to Azure WebJobs logs from a C # console application?

I am testing Azure Webjobs. I wrote a console application that checks the SQL database for a new job and processes it. I do not use the WebJobs SDK because it only supports Azure Storage.

I download the task, it starts, and then it fails with an exception that says it was unable to connect to the SQL Database instance. I am wondering which connection string is being used; this is getting a connection string from an Azure site. The magazines 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 (for example, that a connection string is being used). I tried Console.WriteLine, Debug.WriteLine, Console.Error.WriteLine. None of them appear in my WebJob log.

Apparently, I could get the data by simply throwing an exception with a message body showing what I want, but there should be a better way! How to write SYS INFO and ERR lines to a log?

+44
azure-webjobs
Mar 14 '14 at 22:43
source share
2 answers

Regarding magazines:

For continuous WebJobs, Console.Out and Console.Error are routed to the "application logs", they will be displayed as a repository of files, blocks or tables depending on the configuration of the application logs (similar to your site).

Also, the first 100 lines in each call also fall into the WebJob log file (to ease the debugging pain when WebJob crashes on startup), accessible through the Azure portal (but also stored in the file system of the site on data / workstations / continuous / JobName).

For launched / scheduled WebJobs, Console.Out / Console.Error is routed to the WebJobs startup log file, also accessible using the Azure portal and stored in data / jobs / triggered / jobName / runId.

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

Regarding connection strings:

You can access your connection strings in the same way as on your website using the ConfigurationManager class for WebJobs not written in .NET, you can find these connection strings (and application parameters) as environment variables (anyway as on your website).

+57
Mar 15 '14 at 6:26
source share
โ€” -

I managed to get Console.WriteLine () to leave messages in my web job log. The following console starts 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 shows my log file:

 [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 
+5
Mar 15 '14 at 4:13
source share



All Articles