Generate a log correlation identifier¶
ApiResponseHandler.GenerateId (protected virtual) produces the MessageID used to correlate a client-visible error with its logged/traced entry.
| Field | Value |
|---|---|
| Operation ID | OP-02 |
| Trigger | Post-process an API response, step 6. |
| Inputs | none |
| Outputs | string |
| Primary components | ApiResponseHandler.GenerateId |
| Entry point | src/SAIF.Web.API/ApiResponseHandler.cs |
Steps¶
- Create
Guid.NewGuid()and stringify it (BR-WEBAPI-005). - Concatenate
DateTime.Now.ToString("yyyyMMddHHmmssffffzzz")with the GUID string (BR-WEBAPI-005). - Uses local (not UTC) time.
- Remove all
:characters (so the timezone offset stays URL/token safe) (BR-WEBAPI-005).
Uniqueness across instances is asserted by the MessageIDIsUnique test in src/SAIF.Web.API.Tests/SAIF.Web.API.Tests/ApiResponseHandlerTests.cs. The method is protected virtual, allowing test subclasses to override the correlation-ID strategy.
Process flow¶
flowchart TD
Start([Called from OP-01 step 6]) --> Guid[Guid.NewGuid to string]
Guid --> Concat["Prepend local timestamp<br>yyyyMMddHHmmssffffzzz"]
Concat --> Strip["Remove ':' characters"]
Strip --> End([Return MessageID])
Failure and edge-case behavior¶
- None — the method has no branches and cannot fail.
Related documentation¶
Sources¶
src/SAIF.Web.API/ApiResponseHandler.cssrc/SAIF.Web.API.Tests/SAIF.Web.API.Tests/ApiResponseHandlerTests.cs