问题描述
如何关闭 ASP.NET 为每个请求完成的日志记录,例如
How do I turn off the logging done by ASP.NET for each request e.g.
INFO 09:38:41 用户配置文件可用.使用C:Usersxxxx xxxxAppDataLocalASP.NETDataProtection-Keys"作为密钥存储库和 Windows DPAPI 来加密静态密钥.
DEBUG 09:38:41 托管开始
调试 09:38:41 托管开始
信息 09:38:41 请求开始 HTTP/1.1 GET http://localhost:23369/
信息 09:38:41 请求开始 HTTP/1.1 DEBUG http://localhost:23369/ text/html调试 09:38:41 不支持调试请求
DEBUG 09:38:41 请求路径/与支持的文件类型不匹配
DEBUG 09:38:41 请求成功匹配名称为default"且模板为{controller=Home}/{action=Index}/{id?}"的路由.DEBUG 09:38:41 请求成功匹配名称为default"且模板为{controller=Home}/{action=Index}/{id?}"的路由.调试 09:38:41 执行操作 Forums.Controllers.HomeController.Index
调试 09:38:41 执行操作 Forums.Controllers.HomeController.Index
INFO 09:38:41 使用参数 () 执行操作方法 Forums.Controllers.HomeController.Index - ModelState 有效'
信息 09:38:41 执行操作方法 Forums.Controllers.HomeController.Index
..
我还找不到如何关闭此日志记录...
I couldn't find yet how I can turn this logging off...
这是我在 Startup
类中的 Configure
方法:
This is my Configure
method in the Startup
class:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddProvider(new Log4NetProvider());
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
}
}
catch { }
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseIdentity();
// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
这是我的 project.json 文件:
And this is my project.json file:
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"log4net": "2.0.5",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { }
},
更新:
我的 log4net 提供程序被从这里
推荐答案
我不确定我是否遗漏了什么,但您不只是想提高 Microsoft 日志的日志级别吗?
I'm not sure if I am missing something but don't you just want to raise the log level for the Microsoft logs?
编辑 appsettings.json
(假设 .AddJsonFile("appsettings.json", ...)
)
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "Information"
到
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "None"
或者通过环境变量进行相同的修改(假设 .AddEnvironmentVariables()
)
Or the same modification via environment variables (assumes .AddEnvironmentVariables()
)
Logging:LogLevel:Microsoft=None
您也可以更具体,以下内容减少了大多数条目,但将 Microsoft.AspNetCore.Hosting.Internal.WebHost
留在 Information
.
You can also be more specific, the following reduces most entries but leaves Microsoft.AspNetCore.Hosting.Internal.WebHost
at Information
.
"Microsoft": "Information",
"Microsoft.AspNetCore.Mvc.Internal": "Warning",
"Microsoft.AspNetCore.Authentication": "Warning"
抱歉,如果这不适用于 log4net
Appologies if this doesn't work for log4net
这篇关于如何关闭由 ASP.NET 核心框架完成的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!