Microsoft.Extensions.Logging.AzureAppServices 未显示在 Azure 日志流中
Microsoft.Extensions.Logging.AzureAppServices not showing up in Azure log streams
我觉得我已经尝试了所有方法来获取 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 -> Configure 方法中,您应该添加以下代码行:
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();
这是我Startup.cs中配置方法的代码:
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 门户中显示的日志消息。
我已经在我的项目中安装了相关的 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 -> Configure 方法中,您应该添加以下代码行:
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();
这是我Startup.cs中配置方法的代码:
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 后 -> 启用应用程序日志记录(文件系统),然后在日志流中,我可以看到日志的输出(我在测试中将日志级别设置为详细):