Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Configure logging level in .net console application

I'm writing a .net console application, and I've a problem to set logging levels. I've created appsettings files with "Logging" section, but it doesn't work - I set the level to Error and still gets Info level errors. I know that appsettings are loading correctly because the rest of the settings are correctly binded.

My main class:

static async Task Main(string[] args)
{
    await new HostBuilder()
        .ConfigureAppConfiguration((context, config) =>
        {
            config.AddJsonFile("appsettings.json", true);
            config.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", true, true);
            config.AddEnvironmentVariables();
            if (args != null)
                config.AddCommandLine(args);
        })
        .ConfigureServices((_, services) =>
            services.AddMagic())
        .RunConsoleAsync();
}

and my appsettings.json:

{
  "Postgres": {
    "Host": "localhost",
    "DatabaseName": "db",
    "Username": "admin",
    "Password": "admin",
    "MinLogLevel": "Error"
  },
  "Redis": {
    "Host": "localhost:6379",
    "Password": null
  },
  "Logging": {
    "LogLevel": {
      "Default": "Error"
    }
  }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Adding a direct login configuration resolved my problem:

.ConfigureLogging((context, config) =>                    
    config.AddConfiguration(context.Configuration.GetSection("Logging")))

Whole main function:

static async Task Main(string[] args)
{
    await new HostBuilder()
        .ConfigureAppConfiguration((context, config) =>
        {
            config.AddEnvironmentVariables();
            config.AddJsonFile("appsettings.json", true, true);
            config.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", true, true);
            if (args != null)
                config.AddCommandLine(args);
        })
        .ConfigureLogging((context, config) =>
            config.AddConfiguration(context.Configuration.GetSection("Logging")))
        .ConfigureServices(services =>
            services.AddMagic())
        .RunConsoleAsync();
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!