4

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.

awj
  • 7,482
  • 10
  • 66
  • 120

4 Answers4

4

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 ...");
Sajad Deyargaroo
  • 1,149
  • 1
  • 7
  • 20
  • Thanks for your help, @Sajad. I already had the connection string configured, which is why it's creating a log for each execution of the WebJob). However, I've crawled through the logging provided by the *Toggle* button and none of my `Trace` messages are there. Is it possible that an older version of my WebJob (pre-`Trace`-logging) is cached, even though I've deleted it in the web interface and uploaded a new zip folder? This would also explain why I keep seeing the same exception even though I'm certain that I've fixed it. – awj May 12 '15 at 12:26
  • If you have fixed the error and it is still showing up then your old instance is running. Maybe delete the job and create a new one with new name and they see. – Sajad Deyargaroo May 12 '15 at 12:46
  • No luck, the same exception is still present and none of the `Trace` message are shown - either in the web interface (under "Toggle") or in the blob storage account. Am I using `Trace` correctly? I've updated the original post with a screenshot of my configured diagnostics options. – awj May 12 '15 at 13:05
  • 1
    The connection string mentioned here is for WebJobs SDK specific logs and is not related to the Trace.* traces. – Amit Apple May 12 '15 at 16:00
  • 1
    Enabling application diagnostics is not required. As I mentioned in the reply, you need to specify only the AzureWebJobsDashboard connection string. However, after looking carefully at your code again, I found that you actually need to use Console.Out instead of Trace, I have edited my reply, please take a look and replace your Trace.TraceInformation with Console.Out.WriteLine. Just FYI, I have all this already working in PROD from a long time now. – Sajad Deyargaroo May 12 '15 at 21:27
  • Yes, you're right - `Console.WriteLine` (you don't the `.Out`) does send the messages to the output seen when clicking "Toggle Output". If you modify your answer to explain this then I'll select it as the accepted answer. I'm still puzzled as to how I can write `Trace` messages to the log as explained in that MS article which I linked to. – awj May 13 '15 at 11:45
  • I have removed the .Out, please select this as the accepted answer. Just FYI, you can keep .Out as well, which means the default output that is what I use in my WebJob, – Sajad Deyargaroo May 13 '15 at 22:41
  • Should i use `Console.WriteLine` ? – ManirajSS Jan 11 '16 at 11:12
  • Just for future reference you don't use the quotes its just list this: DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY – sethreidnz Sep 14 '16 at 22:12
4

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.

Community
  • 1
  • 1
DeChrist
  • 530
  • 4
  • 11
  • "Trace is not supported as a default mechanism" --> not true, it is supported. – Amit Apple Sep 03 '15 at 23:43
  • 1
    @AmitApple OK let's say it is "true and supported" as a DEFAULT mechanism. Can you assist me and the OP by providing an answer that substantiates this claim? – DeChrist Sep 07 '15 at 12:12
1

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.

Amit Apple
  • 9,034
  • 41
  • 50
0

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.

ThomasDC
  • 484
  • 3
  • 11