我正在開發一個DotNET核心應用程式,并試圖在Azure應用程式服務中實作Nlogs。在本地機器/Visual Studio上作業時,我成功地生成了Nlogs。然而,當我發布應用程式以在Azure云上部署時,Nlogs并沒有在指定的位置生成。
這是我為發布Nlog所做的配置:---------。 發布配置
在將應用程式部署到云應用程式服務之后,配置看起來像:- 應用程式設定
我沒有收到任何關于應用程式的資訊。
我沒有收到任何錯誤,應用程式作業正常,盡管我沒有看到應用程式服務上生成的任何日志。
uj5u.com熱心網友回復:
在Visual Studio中,創建.Net核心應用程式安裝Nuget包 Microsoft.Extensions.Logging.AzureAppServices,。 和Microsoft.Extensions.Logging.Console,版本為 3.1.2
你的專案。
在Startup.cs的ConfigureServices方法中,添加以下代碼:
public void ConfigureServices(IServiceCollection services) { //其他代碼 //加入以下代碼 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()。
}
- 將應用程式發布到Azure .
- 在Azure Portal中導航到--> App Service Logs,進行以下設定

- 在Azure門戶中導航到"日志流",然后訪問網站,你可以看到日志。
。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/308870.html
標籤:
上一篇:Azure集成服務中的檔案傳輸
下一篇:Azure資料工廠sftp
