I am Working on a DotNET core application and trying to implement Nlogs into Azure App service. While working on Local machine/Visual Studio, I am successfully able to generate Nlogs. However, when I publish the application to deploy on Azure Cloud, Nlogs do not generate at the Specified location.
This is the configuration which I did to publish the Nlog:- Release Configuration
After Deploying the application to cloud app service the configuration looks like:- Application settings
I do not receive any error and application works fine, Though I don't see any logs generated on app service.
CodePudding user response:
In Visual Studio, Create .Net core Application Install Nuget Package Microsoft.Extensions.Logging.AzureAppServices, and Microsoft.Extensions.Logging.Console, version 3.1.2 for your project.
In Startup.cs, ConfigureServices method, add the below code:
public void ConfigureServices(IServiceCollection services) { //other code //add the following code services.AddLogging(loggingBuilder => { loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); loggingBuilder.AddAzureWebAppDiagnostics(); }); }
Add the New Controller class and add the below code:
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();
}
- Publish the Application to Azure .
- In Azure Portal navigate to --> App Service Logs, do the below settings
- Navigate to "Log stream" in azure portal, then visit the web site, you can see the logs: