ekmsystems / serilog-enrichers-correlation-id

Enrich logs with a unique ID so you can track logs for specific requests.
MIT License
93 stars 38 forks source link

Provide a way to provide an output format for CorrelationId #93

Open ovation22 opened 1 year ago

ovation22 commented 1 year ago

Similar to how it's possible to format Level, would it be possible/valuable to format CorrelationId? Ideally first-N characters and/or last-N characters?

Example from LevelOutputFormat:

https://github.com/serilog/serilog/blob/7f1e791c411457eb392a9b4833a5545a90a67ba7/src/Serilog/Formatting/Display/LevelOutputFormat.cs#L20

Proposal:

"w1" (one lowercase char) "e3" (end three chars)

"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3} {CorrelationId:e12}] {Message:lj}{NewLine}{Exception}"

With CorrelationId a103d6e7-e2d0-47b2-8442-120fdc2bb775, would produce:

[18:28:01 DBG 120fdc2bb775] Connection id "0HMMUP8CI08F3" completed keep alive response.