---
title: Generate a log correlation identifier
summary: Produce a unique, time-ordered correlation ID for the current response.
status: draft
owner: andmil
last_reviewed: 2026-09-15
library: SAIF.Web.API
reference_type: package
operation_id: OP-02
trigger: OP-01 (Post-process an API response), step 6.
---

# 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](op-01-post-process-an-api-response.md), step 6. |
| **Inputs** | none |
| **Outputs** | `string` |
| **Primary components** | `ApiResponseHandler.GenerateId` |
| **Entry point** | `src/SAIF.Web.API/ApiResponseHandler.cs` |

## Steps

1. Create `Guid.NewGuid()` and stringify it ([BR-WEBAPI-005](../business-rules.md#br-webapi-005-unique-correlation-identifier-per-response)).
2. Concatenate `DateTime.Now.ToString("yyyyMMddHHmmssffffzzz")` with the GUID string ([BR-WEBAPI-005](../business-rules.md#br-webapi-005-unique-correlation-identifier-per-response)).
   - Uses local (not UTC) time.
3. Remove all `:` characters (so the timezone offset stays URL/token safe) ([BR-WEBAPI-005](../business-rules.md#br-webapi-005-unique-correlation-identifier-per-response)).

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

```mermaid
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
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `src/SAIF.Web.API/ApiResponseHandler.cs`
- `src/SAIF.Web.API.Tests/SAIF.Web.API.Tests/ApiResponseHandlerTests.cs`
