---
title: Format an exception for the error log
summary: Format an exception into a sentinel-delimited error-log entry.
status: draft
owner: saif-docgen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common
reference_type: package
operation_id: OP-022
trigger: Caller writes a caught exception to an error-log store
---

# Format an exception for the error log

Format an exception into a sentinel-delimited error-log entry, triggered when caller writes a caught exception to an error-log store.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-022 |
| **Trigger** | Caller writes a caught exception to an error-log store |
| **Inputs** | `instance` |
| **Outputs** | `string` — short message, sentinel, then full detail |
| **Primary components** | ``ExceptionExtensions.GetErrorLogFormattedException(this Exception)`` |
| **Entry point** | `Common/SAIF.Common/Extensions/ExceptionExtensions.cs` |

## Steps

1. If the exception is null, return `string.Empty`. ([BR-049](../business-rules.md#br-049-formatting-a-null-exception-yields-an-empty-string-rather-than-throwing))
2. Collect the exception chain and reverse it so the innermost exception is first. ([BR-050](<../business-rules.md#br-050-exception-chains-are-reported-innermost-(root-cause)-first-by-default>))
3. Seed a `StringBuilder` with the innermost exception's `Message` — the short summary a log reader sees first. ([BR-052](../business-rules.md#br-052-an-error-log-entry-begins-with-the-innermost-exception's-message%2C-followed-by-the-sentinel-%40%23elog%23%40%2C-followed-by-the-full-report%2C-so-a-log-reader-can-split-summary-from-detail))
4. Append the delimiter constant `ErrorLogMessageString` = `"@#ELOG#@"` to separate summary from detail. ([BR-052](../business-rules.md#br-052-an-error-log-entry-begins-with-the-innermost-exception's-message%2C-followed-by-the-sentinel-%40%23elog%23%40%2C-followed-by-the-full-report%2C-so-a-log-reader-can-split-summary-from-detail))
5. Append the full formatted output of OP-021 and return. ([BR-050](<../business-rules.md#br-050-exception-chains-are-reported-innermost-(root-cause)-first-by-default>), [BR-051](<../business-rules.md#br-051-the-formatted-exception-report-renders-a-summary-block-(type%2C-message%2C-source)-for-every-exception>))

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["Caller writes exception<br>to error log"]) --> C1{"Exception is null?"}
	C1 -->|Yes| Empty([Return string.Empty])
	C1 -->|No| S2["Collect exception chain,<br>reverse so innermost is first"]
	S2 --> S3["Seed StringBuilder with<br>innermost exception's Message"]
	S3 --> S4["Append sentinel '@#ELOG#@'"]
	S4 --> S5["Append full formatted<br>output of OP-021"]
	S5 --> End([Return assembled string])
```

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `Common/SAIF.Common/Extensions/ExceptionExtensions.cs`
