Dispatch audit message¶
This operation records a single audit event, but only once a hosting application has explicitly turned audit logging on. It gathers ambient context (who, where, and in what environment), merges in the caller's message or custom payload, and writes the resulting record to whichever sink is currently active — a local CSV file if one was opened, or the remote wsLogging SOAP service otherwise.
| Field | Value |
|---|---|
| Operation ID | LOG-OP-001 |
| Trigger | Caller invokes clsLogAudit.AuditMessage(...) or clsLogAudit.AuditCustomMessage(...). |
| Inputs | Message text, optional state objects, and for the custom overload performedTo, optional performedBy, optional performedAt, optional overrideApplicationName. |
| Outputs | CSV append or wsLogging.WriteAudit(...) side effect; no return value. |
| Primary components | clsLogAudit.AuditMessage, clsLogAudit.AuditCustomMessage, clsLogAudit.GetBasicAuditInfo, clsLogAudit.WriteMessage |
| Entry point | SAIF.Framework.Logging/clsLogAudit.vb |
Steps¶
- Check
clsLogAudit.IsEnabledfirst; while it isFalse, the operation returns immediately and performs no context capture or sink work (BR-001). - Assemble a baseline
AuditInfoStructinGetBasicAuditInfo(). - Stamp
AuditDate = Nowand clearDataText. - For web hosts (
clsLogCommon.IsWebisTrue), read machine, application, page, and environment values fromHttpContext.ServerandHttpContext.Request, then constructNew clsSecurityPrincipal(clsSecurityPrincipal.Platform.Web). - For non-web hosts, read the executable and environment data from
Process.MainModule, setPageName = "WINFORMS", useEnvironment.MachineName, and constructNew clsSecurityPrincipal(clsSecurityPrincipal.Platform.Windows). - Copy
Secprinc.UserNameintoUserNamewhen the principal resolves one; otherwise leave it empty. - On failure: the helper swallows the exception and returns whatever fields it managed to populate (BR-005).
Origin: The identity-capture in step 2 delegates to
clsSecurityPrincipaland follows the same pattern documented in Principal identity initialization (SAIF.Framework.Security). 3. Merge the caller's payload into the struct. -AuditMessage(...)copiesinMsgintoMessageTextand serializesinStateInfothroughclsLogCommon.GetStateInfo(...), which writes primitive values directly and reflects object properties into name/type/value lines. -AuditCustomMessage(...)copiesperformedTointoDataText, then overrides the audit date, user name, or application name only where the caller supplied an explicit, non-default value. -AuditCustomMessage(...)then replaces the environment text withAppGlobal.EnvironmentService.ToDevelopmentEnvironment(AppGlobal.EnvironmentService.GetApplicationEnvironment()).ToString().Origin: The environment lookup in step 3.3 depends on
IEnvironmentService.GetApplicationEnvironment()fromSAIF.Framework.Security.EnvironmentApi, summarized in Retrieve a configuration setting (SAIF.Framework.Security.EnvironmentApi). 4. Select the output sink inWriteMessage(...). - Ifm_OutFile Is Nothing, continue to the SOAP branch below. - Otherwise appendAuditInfoStruct.ToCSVString()to the open file writer and flush it. 5. In the SOAP branch, resolveloggingServiceUrl, constructwsLogging.clsWSLogging, copy the local struct into awsLogging.AuditInfoStruct, callWriteAudit(...), and dispose the proxy. - On failure: the SOAP branch catches and discards the exception, so the caller always regains control (BR-005).Origin: The
loggingServiceUrllookup in step 5 delegates to Environment API configuration retrieval, summarized in Retrieve a configuration setting (SAIF.Framework.Security.EnvironmentApi).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Audit request]) --> Enabled{IsEnabled?}
Enabled -->|No| EndSkip([Return without logging])
Enabled -->|Yes| Context[Build AuditInfoStruct]
Context --> Payload[Apply message and state/custom overrides]
Payload --> Sink{File sink active?}
Sink -->|Yes| FileWrite[Append CSV row and flush]
Sink -->|No| Resolve[Resolve loggingServiceUrl]
Resolve --> SoapWrite[Call wsLogging.WriteAudit]
FileWrite --> EndOk([Return to caller])
SoapWrite --> EndOk
Failure and edge-case behavior¶
- While
IsEnabledisFalse, the operation exits before touching context or any sink, so disabled audit logging carries no performance cost beyond the flag check (BR-001). - Context capture and the SOAP dispatch both suppress exceptions, so a partially populated or entirely unsent audit record can be dropped silently rather than surfacing a failure to the caller (BR-005).
- Once a file sink has been opened through
ToFile(...), this operation never falls back to the SOAP path for that call.
Related documentation¶
Sources¶
SAIF.Framework.Logging/clsLogAudit.vbSAIF.Framework.Logging/clsLogCommon.vbSAIF.Framework.Logging/AuditInfoStruct.vbSAIF.Framework.Security/clsSecurityPrincipal.vbSAIF.Framework.Security/EnvironmentServices/EnvironmentExtensions.vbSAIF.Framework.Security.EnvironmentApi/Services.Common/EnvironmentServiceBase.csSAIF.Framework.Security.EnvironmentApi/Services.Common/EnvironmentConfigKeys.cs