如何关闭由ASP.NET核心框架完成的日志记录 [英] How to turn off the logging done by the ASP.NET core framework

查看:100
本文介绍了如何关闭由ASP.NET核心框架完成的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何关闭ASP.NET对每个请求的日志记录,例如

How do I turn off the logging done by ASP.NET for each request e.g.

INFO 09:38:41用户个人资料可用.使用"C:\ Users \ xxxx xxxx \ AppData \ Local \ ASP.NET \ DataProtection-Keys"作为密钥存储库,并使用Windows DPAPI加密静态密钥.
DEBUG 09:38:41托管开始
DEBUG 09:38:41托管开始
INFO 09:38:41请求启动HTTP/1.1 GET http://localhost:23369/
INFO 09:38:41请求启动HTTP/1.1调试 http://localhost:23369/ text/html DEBUG 09:38:41不支持DEBUG请求
DEBUG 09:38:41请求路径/与支持的文件类型不匹配
DEBUG 09:38:41请求已成功匹配名称为"default"和模板为"{controller = Home}/{action = Index}/{id?}"的路由. DEBUG 09:38:41请求已成功匹配名称为"default"和模板为"{controller = Home}/{action = Index}/{id?}"的路由. DEBUG 09:38:41执行动作Forums.Controllers.HomeController.Index
DEBUG 09:38:41执行动作Forums.Controllers.HomeController.Index
INFO 09:38:41执行带有参数()的操作方法Forums.Controllers.HomeController.Index-ModelState有效'
INFO 09:38:41执行操作方法Forums.Controllers.HomeController.Index
..

INFO 09:38:41 User profile is available. Using 'C:\Users\xxxx xxxx\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
DEBUG 09:38:41 Hosting starting
DEBUG 09:38:41 Hosting started
INFO 09:38:41 Request starting HTTP/1.1 GET http://localhost:23369/
INFO 09:38:41 Request starting HTTP/1.1 DEBUG http://localhost:23369/ text/html DEBUG 09:38:41 DEBUG requests are not supported
DEBUG 09:38:41 The request path / does not match a supported file type
DEBUG 09:38:41 Request successfully matched the route with name 'default' and template '{controller=Home}/{action=Index}/{id?}'. DEBUG 09:38:41 Request successfully matched the route with name 'default' and template '{controller=Home}/{action=Index}/{id?}'. DEBUG 09:38:41 Executing action Forums.Controllers.HomeController.Index
DEBUG 09:38:41 Executing action Forums.Controllers.HomeController.Index
INFO 09:38:41 Executing action method Forums.Controllers.HomeController.Index with arguments () - ModelState is Valid'
INFO 09:38:41 Executing action method Forums.Controllers.HomeController.Index
..

我仍然找不到如何关闭此记录的方法...

I couldn't find yet how I can turn this logging off...

这是我在Startup类中的Configure方法:

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提供程序从此处 /a>


Update:
My log4net provider was taken from here

推荐答案

我不确定是否遗漏了一些东西,但您不是只想提高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

这篇关于如何关闭由ASP.NET核心框架完成的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆