我的Asp.Net Core API应用托管在Azure上。当将选项Azure > Diagnostic logs > Application Logging (Filesystem) > Level
设置为Information
时,可以在日志流中看到控制器和Entity Framework信息日志,包括SQL查询。我尝试了appsettings.json
:
{ "Logging": {
"LogLevel": {
"Default": "None",
"System": "None",
"Microsoft": "None"
},
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning",
"Microsoft": "None",
"Microsoft.EntityFrameworkCore": "None"
}
},
"Console": {
"LogLevel": {
"Default": "Warning",
"Microsoft": "None",
"Microsoft.EntityFrameworkCore": "None"
}
}
}
}
和Program.cs:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((hostingContext, logging) =>
{
logging.SetMinimumLevel(LogLevel.Warning);
logging.AddAzureWebAppDiagnostics();
logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Error);
})
.UseStartup<Startup>()
.Build();