我觉得我已经尝试了所有方法来获取 Azure 门户中显示的日志消息。
我已经在我的项目中安装了相关的NuGet包:
我已在 Azure 门户中启用日志记录。
我已将以下内容添加到我的 appsettings.json
中:
"AzureLogging": {
"FileName": "azure-diagnostics-",
"FileSizeLimit": 50024,
"RetainedFileCountLimit": 5
}
并在Startup
中添加以下设置代码,以确保它已添加其中之一。
services.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "azure-diagnostics-";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
});
我能从日志中得到的唯一信息如下:
最佳答案
在 Startup.cs -> 配置方法中,您应该添加以下代码行:
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();
这是我的Startup.cs中的Configure方法的代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
//add the following 2 lines of code.
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
发布到azure后 -> 启用应用程序日志记录(文件系统),然后在日志流中,我可以看到日志的输出(我在测试中将日志级别设置为详细):
关于azure - Microsoft.Extensions.Logging.AzureAppServices 未显示在 Azure 日志流中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58269169/