C# 我无法在Azure日志流中看到日志
我正在尝试记录我的ASP.NET核心应用程序的信息,但我找不到在Azure日志流中显示loogs的方法。当我在VisualStudio中调试时,应用程序成功地进行了日志记录,但当我发布到Azure时,没有看到任何内容 我的应用程序服务日志如下所示: 我曾尝试使用我在Microsoft文档中找到的不同方法登录,但都没有成功C# 我无法在Azure日志流中看到日志,c#,azure,logging,azure-web-app-service,asp.net-core-3.1,C#,Azure,Logging,Azure Web App Service,Asp.net Core 3.1,我正在尝试记录我的ASP.NET核心应用程序的信息,但我找不到在Azure日志流中显示loogs的方法。当我在VisualStudio中调试时,应用程序成功地进行了日志记录,但当我发布到Azure时,没有看到任何内容 我的应用程序服务日志如下所示: 我曾尝试使用我在Microsoft文档中找到的不同方法登录,但都没有成功 [HttpGet] public string Index() { Trace.TraceInformation("You are i
[HttpGet]
public string Index()
{
Trace.TraceInformation("You are in the face recognition controller. Trace");
_logger.LogInformation("You are in the face recognition controller. Logger");
return "You are in the face recognition controller";
}
控制器构造函数:
private readonly ILogger _logger;
public FaceRecognitionController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<FaceRecognitionController>();
}
有人知道我能做什么吗
日志流屏幕截图:
对于.NET core 3.1,请按照以下步骤操作: 1.为您的项目安装nuget Packagee和 2.在Startup.cs->ConfigureServices方法中,添加以下代码:
public void ConfigureServices(IServiceCollection services)
{
//other code
//add the following code
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddConsole();
loggingBuilder.AddDebug();
loggingBuilder.AddAzureWebAppDiagnostics();
});
}
然后在控制器类中,代码如下所示:
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
_logger.LogInformation("**********first: hello, this is a test message!!!");
_logger.LogInformation("**********second: hello, this is a test message!!!");
return View();
}
专用只读ILogger\u记录器;
公共家庭控制器(ILogger记录器)
{
_记录器=记录器;
}
公共IActionResult索引()
{
_logger.LogInformation(“************第一:您好,这是一条测试消息!!!”;
_logger.LogInformation(“*********秒:您好,这是一条测试消息!!!”;
返回视图();
}
3.将其发布到azure,然后按照帖子中所述配置“应用程序服务日志”
4.导航至azure portal中的“日志流”,然后访问网站,您可以看到日志:
注意:您应该始终在asp.net core中使用ILogger进行日志记录,Trace.TraceInformation可能不适用于它。您可以附加“Azure日志流”的屏幕截图吗?这是应用程序启动时显示的内容。触发Index()操作时没有显示任何内容。什么是.NETCore版本?2.x或3.x?版本为3.1
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
_logger.LogInformation("**********first: hello, this is a test message!!!");
_logger.LogInformation("**********second: hello, this is a test message!!!");
return View();
}