Skip to content

Add structured logging support#142

Open
andreycha wants to merge 1 commit intohuorswords:developfrom
andreycha:feat/add-structured-logging-support
Open

Add structured logging support#142
andreycha wants to merge 1 commit intohuorswords:developfrom
andreycha:feat/add-structured-logging-support

Conversation

@andreycha
Copy link

@andreycha andreycha commented Apr 12, 2024

Motivation
Structured logging is a standard practice nowadays. When using ILogger and co .NET analyzers even encourage to use it. To comply with the best practice and other logger implementations, this PR adds support for structured logging.

Changes

  • Add message template string and its arguments to logging event properties
  • Expose a method to enrich properties
  • Update documentation

Things to discuss

  • Message template string is added as a property named "MessageTemplate". Motivation for that is to match Serilog implementation. This should make life a bit easier in case people switch between Serilog and log4net. This also makes life easier in case of a service landscape with mixed logger implementations whose logs are then streamed into a central location with unified schema (e.g., Elastic and ElasticCommonSchema).
  • Argument values are currently added as strings to match the same behavior as for scope values. Although I'd strongly advocate for adding at least atomic values as is. Agains, that's how Serilog implementation also behaves.
  • LoggingEventFactory mock was replaced with actual custom implementations in few tests. Main reason is that Moq doesn't allow to mock protected generic method. It also makes test setup easier to understand.
  • I think it would be beneficial (also for us) to have this changes available as early as version 6.

@huorswords huorswords self-assigned this Apr 16, 2024
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

Successfully merging this pull request may close these issues.

2 participants