从App Service中运行的.net核心应用程序发送日志以进行日志分析 [英] Sending logs from .net core application running in App Service to log analytics
问题描述
我试图寻找最简单的.net core 2.0应用程序将应用程序日志发送到日志分析工作区的方法.
此应用程序天蓝色地在App Service下运行,我尝试启用诊断设置"并存档日志以进行日志分析.
但是,我没有在AppServiceHTTPLogs中看到我的应用程序自定义日志消息.
我使用了以下指南:
I tried looking for the simplest way of my .net core 2.0 application to send app logs to log analytics workspace.
This application is running under App Service in azure, and I tried enabling the "Diagnostic Settings" and archiving the logs to log analytics.
However, I am not seeing my app custom logs messages in: AppServiceHTTPLogs .
I have used the following guide: https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html
My application is using ILoggerFactory:
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
loggerFactory.AddDebug();
Any idea of how to ship logs to there?
I test and it works well in my site. You could refer to the following code:
In 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...
}
In HomeController:
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();
}
Configure azure webapp Diagnostics settings as the article and then you will get the appservicehttplogs
. Wait a few minutes, and it will be added to storage automatically.
这篇关于从App Service中运行的.net核心应用程序发送日志以进行日志分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!