问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/60397753/sending-logs-from-net-core-application-running-in-app-service-to-log-analytics