0

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.

Ishan Patel
  • 222
  • 1
  • 6
  • Do you have log levels configured in your environment-specific appsettings, e.g. `appsettings.Development.json`? – poke May 19 '21 at 09:23
  • appsettings.Developement.json and appsettings.json files are the same in my case. – Ishan Patel May 19 '21 at 09:37
  • Does this answer your question? [Suppress SQL Queries logging in Entity Framework core](https://stackoverflow.com/questions/42079956/suppress-sql-queries-logging-in-entity-framework-core) – Ian Kemp May 19 '21 at 10:33
  • Hello, @lan Kemp I already use this answer but this is not working for me. – Ishan Patel May 19 '21 at 12:01

1 Answers1

0

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

mloskot
  • 37,086
  • 11
  • 109
  • 136
Alexrgs
  • 831
  • 8
  • 20