我尝试寻找 .net core 2.0 应用程序将应用程序日志发送到日志分析工作区的最简单方法。
该应用程序在azure中的应用服务下运行,我尝试启用“诊断设置”并将日志存档到日志分析。
但是,我没有在 AppServiceHTTPLogs 中看到我的应用程序自定义日志消息。
我使用了以下指南:https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html
我的应用程序正在使用 ILoggerFactory:
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
loggerFactory.AddDebug();
知道如何将日志运送到那里吗?
我测试过,它在我的网站上运行良好。你可以参考下面的代码:
在startup.cs
:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
other codes...
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
loggerFactory.AddDebug();
app.UseStaticFiles();
other codes...
}
在家庭控制器中:
private readonly ILogger _logger;
public HomeController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HomeController>();
}
public IActionResult Index()
{
_logger.LogInformation("this is a information from ILogger...");
return View();
}
将 azure webapp 诊断设置配置为article https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html然后你会得到appservicehttplogs
。等待几分钟,它会自动添加到存储中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)