How to turn off the logging done by the ASP.NET core framework
I'm not sure if I am missing something but don't you just want to raise the log level for the Microsoft logs?
Edit appsettings.json
(assumes .AddJsonFile("appsettings.json", ...)
)
{ "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Trace", "System": "Information", "Microsoft": "Information"
To
{ "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Trace", "System": "Information", "Microsoft": "None"
Or the same modification via environment variables (assumes .AddEnvironmentVariables()
)
Logging:LogLevel:Microsoft=None
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"
Appologies if this doesn't work for log4net
What have really worked for me was adding this in ASP.NET Core 2.0 project's Startup.cs
file:
using Microsoft.Extensions.Logging;public void ConfigureServices(IServiceCollection services){ . . . services.AddLogging( builder => { builder.AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddFilter("NToastNotify", LogLevel.Warning) .AddConsole(); });}
This way you'll only get Warning level logs for logging info starting with the filters passed to builder.AddFilter
.
My log4net.log file now doesn't show that huge amount of INFO
logging spit by Microsoft and others.
More info here @ Microsoft Docs: Log filtering
If you're using Serilog to do your .NET Core logging, you can update your appsettings.json file to set the log levels like so:
"Serilog": { "MinimumLevel": { "Default": "Verbose", "Override": { "Microsoft": "Error", "System": "Error" } }, "Properties": { "Application": "your-app" }}
This allows you to only log errors from System/Microsoft while logging everything else as you'd like.