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

176
Views
How to access scope message from a Logger

I'm a beginner to Logger, just wondering how does BeginScope() work

// startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger) {
   if (env.IsDevelopment()) {
      app.UseDeveloperExceptionPage();
   }
   app.UseEndpoints(endpoints => {
      endpoints.MapGet("/", async context => {
         using (logger.BeginScope("Example")) {
            logger.LogInformation("Processing credit card payment");
         }
      });
   });
}

enter image description here

I think a scope in logger is the you can add a "prefix" to the logged message, so in my case the output should be "Example Processing credit card payment", so how can I access the scope message "Example" and get in printed in the output?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Set IncludeScopes:true in Program.cs like below:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        })
        .ConfigureLogging(logger => {
            logger.AddConsole(options =>
            {
                options.IncludeScopes = true;
            });
        });

Or you can add IncludeScopes in appsettings.json like this document:Configure logging

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!