简体   繁体   English

日志仅在本地有效,但在部署到Microsoft Azure App Service时无效

[英]Logging only works localy, but not when deployed to Microsoft Azure App Service

i am facing a strange problem while developing an asp.net core application which is deployed to Microsoft Azure and runs there as an app-service. 开发一个部署到Microsoft Azure并作为应用程序服务在那里运行的asp.net核心应用程序时,我遇到一个奇怪的问题。 I target the full .net framework. 我的目标是完整的.net框架。 I am using Microsoft.Extensions.Logging and the logs are working locally without a problem, but when deploying it to Microsoft Azure there are no logs at all. 我正在使用Microsoft.Extensions.Logging ,日志在本地正常运行,但是将其部署到Microsoft Azure时根本没有日志。 The LogStream windows stays empty and just shows the No new Trace in the last n minutes output. LogStream窗口保持空白,并且No new Trace in the last n minutes输出中仅显示No new Trace in the last n minutes

Things I already checked: 我已经检查过的东西:

  • Enabled Diagnostic Logs in the App-Service Settings 应用服务设置中已启用的诊断日志
  • Set the LogLevel there to Verbose 将LogLevel设置为详细
  • Checked the LogFiles directory on the App-Service 检查了App-Service上的LogFiles目录

Part of my appsettings.json 我的appsettings.json的一部分

"Logging": {
 "LogLevel": {
   "Default": "Information"
}

I am then injecting the Logger instances to the controllers like this: 然后,我将Logger实例注入到控制器中,如下所示:

ILogger<FooBarClassName> myLogger;

public FooBarClassName(ILogger<FooBarClassName> logger)
{
        myLogger = logger;
        ....
}

And use it like this: 并像这样使用它:

void SomeMethod()
{
    ...
    myLogger.LogInformation("Some Log Message");
    ...
}    

Thanks for any help to solve this issue. 感谢您为解决此问题提供的帮助。

You could refer to the following steps to check whether you add ILogger correctly. 您可以参考以下步骤检查是否正确添加了ILogger。

Step 1 : 第一步

Go to Startup.cs , inside Configure method add following signature. 转到Startup.cs ,在Configure方法内添加以下签名。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

The ILoggerFactory is default injected into the class by asp.net core. ILoggerFactory默认由asp.net内核注入到类中。

Setp 2 : Setp 2

Set up provider. 设置提供商。

loggerFactory.AddDebug();
loggerFactory.AddAzureWebAppDiagnostics();

The AddAzureWebAppDiagnostics comes from the package . AddAzureWebAppDiagnostics来自该软件包

Setp 3 : Setp 3

Example in my HomeController and the appsettings.json is same with you: 我的HomeController和appsettings.json示例与您相同:

private readonly ILogger _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }
        void SomeMethod()
        {
            _logger.LogInformation("some log message.");
        }
        public IActionResult Index()
        {
            SomeMethod();
            return View();
        }

Step 4 : 第四步

Set diagnostic logs to turn on applicaiton logging 设置诊断日志以打开应用程序日志记录

在此处输入图片说明

Step 5 : 步骤5

See logs in Log Stream 查看日志流中的日志

在此处输入图片说明

For more details, you could refer to this case and this article . 有关更多详细信息,您可以参考此案例本文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure应用程序可在开发架构上运行,但在部署时无法运行 - Azure app works on dev fabric but not when deployed Ocelot 部署到 azure 应用服务时找不到 api - Ocelot can't find api when deployed to azure app service 部署到 Azure 应用服务时下载文件失败 - Failed to download files when deployed to Azure App Service Microsoft Azure应用服务存储 - Microsoft Azure App Service Storage 是什么导致本地化成功后已部署服务中的反序列化失败? - What could cause a deserialization in a deployed service to fail while it succeeds localy? 访问拒绝运行远程PowerShell,但仅当从开发服务器运行时才能正常工作 - Access Denied running Remote PowerShell but only when ran from dev server, works fine localy 简单的WebClient在本地工作,但在部署到Azure时无法工作 - Simple WebClient works locally, but not when deployed to Azure 部署到 Azure 应用服务的 WorkerService 未启动 - WorkerService deployed to Azure App Service is not starting Azure上的C#MVC应用程序:新部署时站点工作正常,但闲置后失败 - C# MVC app on Azure: Site works fine when freshly deployed but fails after being left idle Asp.net 会员提供程序无法连接到内部部署 SQL 服务器部署到 Azure 应用程序服务 - Asp.net Membership provider fails to connect to on premise SQL Server when deployed to Azure app service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM