简体   繁体   中英

How do I turn off the default logging done by ASP.NET and Entity Framework for each request?

How do I turn off the default logging done by ASP.NET and Entity Framework for each request?

I couldn't find yet how I can turn this logging off. I Use Asp.NET Core 3.1 and Serilog.Extensions.Logging.File

I am getting the multiple entity framework logs like Executed DbCommand and much more. When I run the project and close then it can generate 1000+ lines log. This is my log file.

2021-05-18T15:05:00.3079413+05:30 80000004-0000-e500-b63f-84710c7967bb [INF] Request finished in 2474.1038ms 200 application/json; charset=utf-8 (791a596a)
2021-05-18T15:05:00.3157337+05:30 80000008-0000-f100-b63f-84710c7967bb [INF] Executed DbCommand ("73"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"
""SELECT TOP(1) [h].[HeaderCurrencyBarID], [h].[EURBuy], [h].[EURSell], [h].[ModifiedOn], [h].[USDBuy], [h].[USDSell]
FROM [HeaderCurrencyBar] AS [h]
ORDER BY [h].[ModifiedOn] DESC, [h].[HeaderCurrencyBarID] DESC" (0723d8ff)

This is my Configure method in the Program class:

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
    })
    .ConfigureLogging((hostingContext, logging) =>
    {
        logging.ClearProviders();
        logging.AddConfiguration((IConfiguration)hostingContext.Configuration.GetSection("Logging"));
        logging.AddFile("Logs/log.txt", retainedFileCountLimit: 31);
    });

This is my appsettting.json file

"Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft": "None",
      "Microsoft.Hosting.Lifetime": "None"
    }
  },

I want to delete 1 month's older log files automatically. I already setup in this project but it is not working.

I attached sample project here .

Assuming you logging settings are been loaded properly on ConfigureLogging

Change your appsettting.json file to:

"Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft": "None",
      "Microsoft.Hosting.Lifetime": "None"
      "Microsoft.EntityFrameworkCore": "None"
    }
  },

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM