Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ILogger在本地登录app insights,但不在azure上登录_C#_Azure_Azure Application Insights_Webjob_Appinsights - Fatal编程技术网

C# ILogger在本地登录app insights,但不在azure上登录

C# ILogger在本地登录app insights,但不在azure上登录,c#,azure,azure-application-insights,webjob,appinsights,C#,Azure,Azure Application Insights,Webjob,Appinsights,以下代码在我的机器上本地工作。这意味着在几分钟后,所有日志语句都将在应用程序中显示 当我使用Publish as Webjob部署应用程序时,所有的应用程序都会部署,但是没有触发的Webjob的日志语句,尽管我可以看到它每5秒运行一次 我还试过线程。Sleep(30000);//30秒 为什么app insights在本地工作,但不在azure上托管 控制台应用程序.NET 4.7.2: // Create the DI container. IService

以下代码在我的机器上本地工作。这意味着在几分钟后,所有日志语句都将在应用程序中显示

当我使用Publish as Webjob部署应用程序时,所有的应用程序都会部署,但是没有触发的Webjob的日志语句,尽管我可以看到它每5秒运行一次

我还试过线程。Sleep(30000);//30秒

为什么app insights在本地工作,但不在azure上托管

控制台应用程序.NET 4.7.2:

  // Create the DI container.
                IServiceCollection services = new ServiceCollection();
    
                var appInsightsKey = ConfigurationManager.AppSettings.Get("APPINSIGHTS_INSTRUMENTATIONKEY");
                Console.WriteLine($"appInsightsKey: {appInsightsKey}");
    
                // Being a regular console app, there is no appsettings.json or configuration providers enabled by default.
                // Hence instrumentation key and any changes to default logging level must be specified here.
                services.AddLogging(loggingBuilder =>
                {
                    loggingBuilder.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Information);
                    loggingBuilder.AddApplicationInsights(appInsightsKey);
                }
                );
    
                services.AddApplicationInsightsTelemetryWorkerService(appInsightsKey);
                IServiceProvider serviceProvider = services.BuildServiceProvider();
                // Obtain logger instance from DI.
                ILogger<Program> logger = serviceProvider.GetRequiredService<ILogger<Program>>();
    
                logger.LogWarning("nogger 2: warning");
                logger.LogInformation("nogger2: information");
                logger.LogError("nogger2: error");
    
                Console.WriteLine("This is the end...");
    
                Task.Delay(5000).Wait();
//创建DI容器。
IServiceCollection服务=新的ServiceCollection();
var appInsightsKey=ConfigurationManager.AppSettings.Get(“APPINSIGHTS_INSTRUMENTATIONKEY”);
WriteLine($“appInsightsKey:{appInsightsKey}”);
//作为常规控制台应用程序,默认情况下没有启用appsettings.json或配置提供程序。
//因此,必须在此处指定检测键和对默认日志记录级别的任何更改。
services.AddLogging(loggingBuilder=>
{
loggingBuilder.AddFilter

向下滚动查看.NET framework控制台应用程序

我注意到了一些有趣的事情(引用的不同显示…),但可能最终不会有任何区别,因为对于这两个项目,azure中的iLogg不起作用:

4.7.2项目:

4.6.1项目:


我也刚刚使用调试模式部署为Azure Webjob vom Visual Studio,但它仍然不起作用,我甚至在部署对话框中配置了appinsights extra,但没有区别!

您好,您是否检查了应用程序服务的配置?是否启用了appinsights并正确设置了连接字符串?如我阅读appInsi的代码中所述ghtsKey成功地在控制台日志中创建了它…必须启用应用程序洞察,因为它在本地工作…但实际上它已启用!可能是因为本地没有创建ApplicationInsights.config?可能azure代码需要它…我不记得是哪个进程在创建该文件,可能是在我添加任何appinsights nuget时…@HelloWorld wh您正在使用ich sdk?请参阅我的更新答案!:-)