serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
309 stars 99 forks source link

Required properties not provided for... warning when property is specified on Context #123

Closed flin-8 closed 5 years ago

flin-8 commented 5 years ago

I've code some code that looks like:

logger2 = _logger
                .ForContext("ControllerName", controllerName)
                .ForContext("ControllerAction", controllerAction);
logger2.Debug("Obtaining lock for {ControllerName}/{ControllerAction}");

The selflog shows a warning: 2018-09-28T02:32:19.0176864Z Required properties not provided for: Obtaining lock for {ControllerName}/{ControllerAction}

What's the expected behaviour?

adamchester commented 5 years ago

Hi @flin-zap, that is the expected behaviour.

The reason is because the logger methods including Debug expect you pass the template properties as parameters to that method, along with the template. This is similar to String.Format.

The context properties are not supposed to be used for the template event properties.

See https://github.com/serilog/serilog/wiki/Writing-Log-Events for example.