[英]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: 我已经检查过的东西:
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.