Logging to Text File

Ronald Rex 1,671 Reputation points
2022-08-01T22:17:36.563+00:00

I'm trying to follow along with a tutorial at the following link https://www.roundthecode.com/dotnet/create-your-own-logging-provider-to-log-to-text-files-in-net-core that will add logging to my application. But when i look at my Program.cs file I dont know where to put the below code. Thank You !!!

public class Program  
{  
    ...  
       
    public static IHostBuilder CreateHostBuilder(string[] args) =>  
        Host.CreateDefaultBuilder(args)  
            .ConfigureWebHostDefaults(webBuilder =>  
            {  
                webBuilder.UseStartup<Startup>();  
            })  
            .ConfigureLogging((hostBuilderContext, logging) =>  
            {  
                logging.AddRoundTheCodeFileLogger(options =>  
                {  
                    hostBuilderContext.Configuration.GetSection("Logging").GetSection("RoundTheCodeFile").GetSection("Options").Bind(options);  
                });  
            });  
}  
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CowieCowie 76 Reputation points
    2022-08-02T02:30:01.477+00:00

    Hi Ronald, you should put your code in your program.cs like the pic below
    Hope it helps~

    226957-screenshot-2022-08-02-102815.png


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.