serilog-extensions-hosting icon indicating copy to clipboard operation
serilog-extensions-hosting copied to clipboard

Positional format parameters not correct

Open jmajoor opened this issue 3 years ago • 1 comments

When I use the Serilog extensions then my positional format parameters are incorrectly formatted.

The following example:

` class Program {

    public static void Main(string[] args)
    {
        
        var builder = Host.CreateDefaultBuilder(args);

        builder
            .ConfigureServices((context, services) =>
            {
                services.AddHostedService<Test>();
            })
            .UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
                .MinimumLevel.Information()
                .WriteTo.Console())
            .UseConsoleLifetime()
            .Build().Run();
    }

    class Test : IHostedService
    {
        private readonly ILogger<Test> _logger;

        public Test(ILogger<Test> logger)
        {
            _logger = logger;
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine(".NET Core string.Format {1}/{0}", "second", "first");
            _logger.LogInformation("SeriLogExtensions {1}/{0}", "second", "first");
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }
    }
}`

Note that the format string does not have the positional parameters in the same order as the arguments.

The .NET Console writeline will print first/second, but when using the serilog extensions I have the reverse.

Expected: .NET Core string.Format first/second [15:30:57 INF] SeriLogExtensions first/second

Actual: .NET Core string.Format first/second [15:30:57 INF] SeriLogExtensions second/first

jmajoor avatar Apr 23 '21 22:04 jmajoor

Sorry, ignore my comment! Just realized you're already doing that; I'll move this issue over to that repository.

nblumhardt avatar Apr 24 '21 00:04 nblumhardt