Class StructuredLogSinkResolver
Pure resolution rules for multi-instance structured log sinks, extracted from the
composition root so they are unit-testable without booting: bare-key resolution (only
unambiguous with exactly one installed instance), structured:{Id} instance keys
(case-insensitive prefix, case-preserved Id), first-wins Id registration, and the strict
empty-Id skip rule for multi-instance configurations.
Inherited Members
Namespace: Serenity.StructuredLogging.Installation.Installers
Assembly: Serenity.UnityStructuredLogging.Installation.dll
Syntax
public static class StructuredLogSinkResolver
Fields
InstanceKeyPrefix
The logger-key prefix selecting a structured sink instance by its settings Id.
Declaration
public const string InstanceKeyPrefix = "structured:"
Field Value
| Type | Description |
|---|---|
| string |
Methods
CountConfiguredInstances<TSettings>(IReadOnlyList<TSettings>)
Counts the actually configured instances in a settings list: only non-null entries count. Empty inspector slots (Unity's list "+" button adds null entries) must not inflate the count, or a single real instance with a deliberately blank Id would be skipped by ShouldSkipForEmptyId(string, int) as if it had siblings.
Declaration
public static int CountConfiguredInstances<TSettings>(IReadOnlyList<TSettings> configuredInstances) where TSettings : class
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<TSettings> | configuredInstances | The configured settings list, or null. |
Returns
| Type | Description |
|---|---|
| int | The number of non-null entries. |
Type Parameters
| Name | Description |
|---|---|
| TSettings | The settings entry type. |
IsBareKeyAmbiguous(IReadOnlyList<ILogService>)
Reports whether the bare structured key is ambiguous: more than one installed instance.
Declaration
public static bool IsBareKeyAmbiguous(IReadOnlyList<ILogService> installedServices)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<ILogService> | installedServices | The installed structured sink services. |
Returns
| Type | Description |
|---|---|
| bool |
ResolveBareKey(IReadOnlyList<ILogService>)
Resolves the bare structured key: only exactly one installed instance is
unambiguous. Zero or multiple instances resolve to null — use
IsBareKeyAmbiguous(IReadOnlyList<ILogService>) to tell the two apart for reporting.
Declaration
public static ILogService ResolveBareKey(IReadOnlyList<ILogService> installedServices)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<ILogService> | installedServices | The installed structured sink services, in install order. |
Returns
| Type | Description |
|---|---|
| ILogService | The single installed service, or null. |
ResolveInstanceKey(IReadOnlyDictionary<string, ILogService>, string)
Resolves a structured:{Id} key against the Id map. Ids compare case-sensitively (ordinal).
Declaration
public static ILogService ResolveInstanceKey(IReadOnlyDictionary<string, ILogService> servicesById, string instanceId)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyDictionary<string, ILogService> | servicesById | The installed services keyed by their settings Id. |
| string | instanceId | The requested instance Id. |
Returns
| Type | Description |
|---|---|
| ILogService | The matching service, or null when the Id is unknown. |
ShouldSkipForEmptyId(string, int)
The strict multi-instance identity rule: with more than one configured instance, an
instance without a non-blank Id cannot be addressed and is skipped. A single configured
instance may leave its Id empty (the bare structured key still resolves it).
Declaration
public static bool ShouldSkipForEmptyId(string instanceId, int configuredInstanceCount)
Parameters
| Type | Name | Description |
|---|---|---|
| string | instanceId | The instance's settings Id. |
| int | configuredInstanceCount | How many instances the composition root configures, from CountConfiguredInstances<TSettings>(IReadOnlyList<TSettings>). |
Returns
| Type | Description |
|---|---|
| bool | True when the instance must be skipped. |
TryExtractInstanceId(string, out string)
Extracts the instance Id from a structured:{Id} logger key. The prefix matches
case-insensitively; the Id is taken from the original key with its case preserved. A key
without the prefix — or with nothing after it — does not match.
Declaration
public static bool TryExtractInstanceId(string trimmedKey, out string instanceId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | trimmedKey | The trimmed logger key to inspect. |
| string | instanceId | The extracted, case-preserved instance Id, or null. |
Returns
| Type | Description |
|---|---|
| bool | True when the key is an instance key with a non-empty Id. |
TryRegisterInstance(IDictionary<string, ILogService>, string, ILogService)
Registers an installed instance under its Id with first-wins semantics: a duplicate Id is rejected and the map keeps the first registration.
Declaration
public static bool TryRegisterInstance(IDictionary<string, ILogService> servicesById, string instanceId, ILogService service)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, ILogService> | servicesById | The Id map to register into. |
| string | instanceId | The instance's non-empty settings Id. |
| ILogService | service | The installed service. |
Returns
| Type | Description |
|---|---|
| bool | True when registered; false when the Id was already taken (first wins). |