Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positional format parameters not correct #45

Open
jmajoor opened this issue Apr 23, 2021 · 1 comment
Open

Positional format parameters not correct #45

jmajoor opened this issue Apr 23, 2021 · 1 comment

Comments

@jmajoor
Copy link

jmajoor commented Apr 23, 2021

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

@nblumhardt
Copy link
Member

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

@nblumhardt nblumhardt transferred this issue from serilog/serilog-extensions-logging Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants