This is a small experiment asp.net project which tries to implement an easy to use solution for structured logging.
Things I want in a structured log system:
- easy to understand scope lifetimes for added properties
- for api requests, a scope should be available for the lifetime of the request
- support for adding properties to an existing scope from within a child async context
The approach taken here is to use an async local dictionary for holding log properties and a middleware for creating a scope which wraps as much of the lifetime of a request as possible.
Code within the lifecycle of a request can add new log scope properties by calling static log context helper functions which updates the async local dictionary of properties.