1

In a .Net Core Webapi project I am using Serilog to log. But when I use _logger.LogInformation("Token for user {UserName} created",data.username); and check the log file, the output is "Token for user {Username} created". The {Username} is not replaced with the real value. I am sure that the value is not null.

I use this in a LoginService and the Serilog setting in the appsetting.json is

"Serilog": {
  "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
  "MinimumLevel": {
    "Default": "Debug",
    "Override": {
      "Microsoft": "Information",
      "System": "Information"
    }
  },
  "WriteTo": [
    { "Name": "Console" },
    {
      "Name": "File",
      "Args": {
        "path": "C:\\Users\\ab\\Projects\\IQC\\IQC_Log.txt",
        "rollingInterval": "Day",
        "rollOnFileSizeLimit": true,
        "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter"
      }
    }
  ]
}

Could someone help to point out where I did wrong?

1
  • normally an unexpanded braced identifier is down to an entirely missing argument, i.e. that would happen if you didnt pass any arguments. Given its not sink specific, I'd say this whole question is independent of which sink(s) is orthogonal. Commented Mar 14, 2024 at 23:53

1 Answer 1

0

Assuming you're getting JSON in that file as expected, the problem will be that you're using CompactJsonFormatter, which does not render message templates.

Instead, you need to pass Serilog.Formatting.Compact.RenderedCompactJsonFormatter for the formatter arg.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.