OP-02: Configure the Windows Service logger (SaifWindowsServiceLog)¶
| Field | Value |
|---|---|
| Operation ID | OP-02 |
| Trigger | Host Windows Service calls SaifWindowsServiceLog.Configure(IEnvironmentClient, IHttpJsonClient) during service startup. |
| Inputs | IEnvironmentClient, IHttpJsonClient. |
| Outputs | A configured Serilog pipeline with an Event Log sink (manageEventSource: true), the Logging API sink (error route unset), and a Console sink; IsConfigured set to true. |
| Primary components | SaifWindowsServiceLog, SaifLogBase, ApiLoggerConfig, EventLogConfig |
| Entry point | SaifWindowsServiceLog.Configure |
Steps¶
- Call
ConfigureLoggers(environmentClient), which resolves the base log threshold using the same application-section-then-tracingdefaultsfallback as the web logger (BR-LOG-01, BR-LOG-02). - Parse the threshold; an unparseable or empty value throws
ArgumentExceptionand aborts configuration (BR-LOG-08). - Still inside
ConfigureLoggers: build the standardEventLogConfig(Level = LogLevel.Info) andApiLoggerConfigsink configurations, then apply theSaifLogging:BaseLevelandSaifLogging:Loggersappsettings.jsonoverrides, same as the web logger: - 3.1. Check whether the
SaifLoggingsection exists and contains aBaseLevelchild; only then replaceBaseLevelwith that configured value (normalized viaToLogLevelString()) — an absent section or key leaves the Environment-API-derivedBaseLevelfrom steps 1–2 untouched (BR-LOG-02). - 3.2. Check whether
SaifLogging:Loggersexists; for each child entry, parseType/Level/LogPatternand replace the matching standardApiLog/EventLogconfig wholesale, throwingSaifLogConfigurationExceptionfor an invalidTypeorArgumentExceptionfor a missingLevel(BR-LOG-03, BR-LOG-04, BR-LOG-05).
Origin: Steps 3.1–3.2 are implemented in Apply appsettings.json logger overrides (
SaifLogBase.ApplyLoggingSettingOverrides) and executed on behalf of this operation. 4. Back inConfigure: compute the Event Log source name as{EnvironmentTrackName.ToUpper().First()}{EnvironmentTrackName.ToUpper().Last()}-{ApplicationName}. 5. Readtracingdefaults:loggingapiurlandtracingdefaults:logroute— but notlogerrorroute— and push the base URL into the injectedIHttpJsonClient(BR-LOG-09). 6. Construct the Serilog logger with the resolvedBaseLevelSwitch, an Event Log sink built withmanageEventSource: true, aLoggingApiSink, and a Console sink. 7. SetIsConfigured = true.
Process flow¶
flowchart TD
A[Configure called] --> B["ConfigureLoggers: resolve base threshold"]
B --> C{Threshold valid?}
C -->|No| C1[ArgumentException - Configure aborts]
C -->|Yes| D["Build standard EventLogConfig + ApiLoggerConfig,<br>apply BaseLevel/Loggers overrides"]
D --> E["Compute Event Log source name<br>from track name + ApplicationName"]
E --> F[Read loggingapiurl / logroute only - no logerrorroute]
F --> G[Push base URL into IHttpJsonClient]
G --> H["Build Serilog logger: Event Log sink<br>(manageEventSource) + LoggingApiSink + Console sink"]
H --> I["IsConfigured = true"]
Failure and edge-case behavior¶
- Same threshold-resolution failure mode as the web logger: an invalid/missing threshold aborts this
Configurecall;IsConfiguredstaysfalseif this is the first attempt, or keeps its priortruevalue if a previously-successfulConfigureis being retried (BR-LOG-08). - Because
logerrorrouteis never read, every error entry this logger posts is sent with anullerror route, regardless of what the Environment API holds for that key (BR-LOG-09). - An empty
EnvironmentTrackNamefrom the host'sIEnvironmentClientcan throw when composing the Event Log source, since the code upper-cases and takes the first and last characters of the track name.
Related documentation¶
Sources¶
src/SAIF.NetCore.Logging/SAIF.NetCore.Logging/SAIF.NetCore.Logging/SaifWindowsServiceLog.cssrc/SAIF.NetCore.Logging/SAIF.NetCore.Logging/SAIF.NetCore.Logging/SaifLogBase.cs