我正在尝试为测试应用程序设置分析:
public void ProcessQueueMessage(
[BlobTrigger("blob-injector/{name}")] CloudBlockBlob blob,
string name,
[Queue("invoice")] ICollector<string> output,
[Blob("blob-archive/{name}")] CloudBlockBlob archive,
TraceWriter log)
{
log.Info($"Started processing {name}");
string content = blob.DownloadText();
log.Info($"retrieved file {name}{Environment.NewLine}{content}");
output.Add(content);
log.Info($"{name} added to queue");
archive.UploadText(content);
log.Info($"{name} has been archived");
blob.DeleteIfExists();
log.Info($"Completed processing {name}");
}
,并且我已将appInsights实例添加到我的azure订阅中。我从App服务获取一些日志记录:
我将诊断日志记录设置为记录到Blob存储,并且可以在此处找到我的日志。我发现的所有信息似乎都表明我所需要的一切。但是我在Application Insights中找不到日志。
[编辑} 如果相关,这是一个.net 4.6.1 WebJob。
[更新] 我将其更改为使用TelemetryClient,并获得了日志。
答案 0 :(得分:1)
假设您正在使用Microsoft.Azure.WebJobs.Logging.ApplicationInsights 2.2.0
。
我可以看到TraceWriter日志按照以下步骤/代码进入分析:
1。创建一个.net framework 4.6.1 webjob
2。在Visual Studio Nuget软件包管理器中,安装以下版本的软件包:
Microsoft.Azure.WebJobs.Logging.ApplicationInsights 2.2.0
System.Configuration.ConfigurationManager 4.5.0
Microsoft.Extensions.Logging.Console 2.1.1
3。在app.config文件中,添加以下内容(用于本地测试):
AzureWebJobsDashboard, AzureWebJobsStorage, APPINSIGHTS_INSTRUMENTATIONKEY
4。在您的Azure Web应用程序->应用程序设置中,添加AzureWebJobsDashboard
和APPINSIGHTS_INSTRUMENTATIONKEY
,屏幕截图如下所示:
5。在Main()
方法中,添加以下代码:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Configuration;
namespace WebJob8
{
class Program
{
static void Main()
{
using (var loggerFactory = new LoggerFactory())
{
var config = new JobHostConfiguration();
var instrumentationKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"];
config.DashboardConnectionString = "";
config.LoggerFactory = loggerFactory
.AddApplicationInsights(instrumentationKey, null)
.AddConsole();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
}
}
}
6.Functions.cs中的代码:
public class Functions
{
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TraceWriter log)
{
log.Info("1113 this is a queue message: "+message);
log.Info("1113 it is a test from azure web jobs!!!");
}
}
7。将Web作业发布到Azure,运行它,然后导航到Azure Portal->您的应用程序见解->搜索,您可以看到日志消息: