我有以下代码:
public static void Main()
{
_servicesBusConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
_namespaceManager = NamespaceManager.CreateFromConnectionString(_servicesBusConnectionString);
_applicationInsightsInstrumentationKey = ConfigurationManager.AppSettings["appInsightsInstrumentationKey"];
JobHostConfiguration config = new JobHostConfiguration();
ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration
{
ConnectionString = _servicesBusConnectionString
};
config.UseServiceBus(serviceBusConfig);
config.LoggerFactory = new LoggerFactory()
.AddApplicationInsights(_applicationInsightsInstrumentationKey, null)
.AddConsole();
config.Tracing.ConsoleLevel = TraceLevel.Off;
var host = new JobHost(config);
host.RunAndBlock();
}
和功能:
public static async Task ProcessMessages([ServiceBusTrigger(ServiceBusQueueNames.SomeQueueName)]BrokeredMessage brokeredMessage, TextWriter log)
{
try
{
_log = log;
_log.WriteLine("WebJob started processing of a message");
await _log.FlushAsync();}
它将消息记录到控制台,但不记录到ApplicationInsights。 工具键设置正确。
您能否说出为什么它不登录到ApplicationInsights?
我已经相应地编写了这段代码https://github.com/Azure/azure-webjobs-sdk/wiki/Application-Insights-Integration
答案 0 :(得分:0)
首先要检查:您的检测密钥在运行时有效吗?
然后,如果ikey是您期望的样子,那么它是您期望的资源(您不是在查看dev应用程序见解实例,而是遥测将在prod实例上进行?)< / p>
如果您在本地调试,您是否看到应用程序见解程序集正在加载? 您在运行调试器的情况下从应用程序见解中看到控制台输出吗?