Azure WebJobs: Can't find Trace logging

好久不见. 提交于 2021-01-27 07:51:35

问题


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.


回答1:


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 ...");



回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/30184628/azure-webjobs-cant-find-trace-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!