ilya-chumakov / LoggingAdvanced

Improved and patched .NET Core console logger.
Apache License 2.0
22 stars 4 forks source link

compatibility .net core 3.1 #13

Closed HenriApperloo closed 4 years ago

HenriApperloo commented 4 years ago

When comes the compatibility .net core 3.1 version ?

ilya-chumakov commented 4 years ago

When comes the compatibility .net core 3.1 version ?

Sure. This week.

ilya-chumakov commented 4 years ago

When comes the compatibility .net core 3.1 version ?

Sorry for the delay. It seems a new release is not needed. I created a netcoreapp3.1 targeted ASP.NET Core project and made it work. The only code change is to remove the default console provider and register LoggingAdvanced:

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging((hostingContext, builder) =>
                {
                    builder.ClearProviders();

                    var loggingSection = hostingContext.Configuration.GetSection("Logging");

                    builder.AddConfiguration(loggingSection);
                    builder.AddConsoleAdvanced(loggingSection);
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

P.S. I don't have any 3.1 real-world projects right now so your feedback is very appreciated.

HenriApperloo commented 4 years ago

Thanks, I add the logger to a .Net Core 3.1 Console Application.

  webBuilder.ConfigureLogging((hostingContext, loggingBuilder) =>
                    {
                        var loggingSection = hostingContext.Configuration.GetSection("Logging");

                        loggingBuilder.AddConsoleAdvanced(loggingSection);
                    });

It works but...see example below sometimes no date and time. sometime date and time before or after info: Datetime fore color wil not following the status color: Info(green), error(red), etc

info: Microsoft.Hosting.Lifetime[0] Now listening on: http://[::]:60064

info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:5001 [2020.03.30 13:01:50] info: Lifetime: Now listening on: http://localhost:5001 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. [2020.03.30 13:01:50] info: Lifetime: Application started. Press Ctrl+C to shut down. info[2020.03.30 13:01:50] : Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Lifetime: Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: C:\ProjectsCheckOut\APIGateway\ApiServer [2020.03.30 13:01:50] info: Lifetime: Content root path: C:\ProjectsCheckOut\APIGateway\ApiServer

ilya-chumakov commented 4 years ago

@HenriApperloo that's because a default console logger is still enabled. There are two solutions:

1) Call builder.ClearProviders(); as shown above, then add only those you need (AddDebug for example) 2) Don't call Host.CreateDefaultBuilder(args) and create a builder from scratch, then you can avoid unnecessary AddConsole calls.

HenriApperloo commented 4 years ago

It works! I had overlooked that row.

Thanks