4
votes

I've followed the instructions on this Microsoft webpage for logging messages from an Azure WebJob, but none of my messages appear in the log.

In my WebJob I write logging messages using

Trace.TraceInformation("blah blah blah");

In the configuration file's application diagnostics section I have blob storage logging turned on with the "Verbose" option.

Log files are being created (though I sometimes have to wait several minutes - in one case until the following morning - until the logs appear in the blob storage) but the logs don't contain my Trace messages.

So how do I log messages to these log files, and/or where does Trace get written to?

Here is an image of my configured options for logging:

enter image description here

And the configured blob storage is definitely the same as the one I'm looking in.

4

4 Answers

4
votes

To specify the storage account for Web Job logs, you need to add connection string under CONFIGURE tab > connection string sections, name of the connection string has to be AzureWebJobsDashboard.

It should be look like below:

  • Name: AzureWebJobsDashboard
  • Value: DefaultEndpointsProtocol=https;AccountName="";AccountKey=""
  • Type: Custom

You can also view logs in Azure portal, open the Web app and select WEBJOBS tab, click on the URL of web job, it will show the last runs, click on Toggle button, which shown details of the run including the custom messages written by app using below statement.

Console.WriteLine("Error While Doing Something ...");
4
votes

Azure WebJobs offer two mechanisms of sending output to the log visible on the WebJobs SDK dashboard:

  1. Static methods of the Console class (e.g. Console.WriteLine)
  2. Usage of a TextWriter object that you get as the "log" parameter of your methods decorated by one or more attributes of the SDK (e.g. [NoAutomaticTrigger])

Effectively, this explains the question that you have:

  • The logging mechanism provided in Azure WebJobs (that supports Trace natively) is unrelated to the one used in Azure web apps (this previous answer to this question explains how to configure the logging)
  • Trace is not supported as a default mechanism, which explains why you "Can't find Trace logging"

It is however easy in both cases to add a TraceListener that will capture the output of your Trace statements.

This answer explains how to do it for the Console.
And, the log object can be added as a TextWriterTraceListener.

This worked as expected for me.

1
votes

To easily view your WebJob and Website logs you can use the Azure Website Log Browser site extension, find our more information on installing it here - http://blog.amitapple.com/post/2014/06/azure-website-logging/.

If you still don't see your logs there or if it takes a long time for them to show (it shouldn't) start a thread on the msdn forum which would be more appropriate for these kind of issues.

0
votes

I also couldn't find my Trace logs until I restarted the App Service from the Portal.

Trace logs should work just fine as mentioned here and are stored under D:\home\LogFiles\application.