Console log service discovery¶
ConsoleLogService's constructor discovers machine-scoped OS environment variables that identify numbered log files and registers a LogWriter for each match, in addition to console output used throughout the console application lifecycle.
| Field | Value |
|---|---|
| Operation ID | OP-WIN-006 |
| Trigger | Autofac resolution of IConsoleLogService (registered by dependency and unit-of-work registration). |
| Inputs | Machine-scoped environment variables (Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine)). |
| Outputs | A populated loggers list of LogWriter instances. |
| Primary components | ConsoleLogService constructor, RegisterLogFile, LogWriter constructor |
| Entry point | Console\SAIF.Console\Console\ConsoleLogService.cs |
Steps¶
- Filter machine environment variable names matching regex
^file[0-4](case-insensitive, lower-cased before matching). - For each matching variable name, call
RegisterLogFile(key, Environment.GetEnvironmentVariable(key)), which addsnew LogWriter(logId, filePath)to theloggerslist. LogWriter's constructor mapslogId.ToLower()to aLogType(file0–file4, elseCustom) via a fixed lookup dictionary (BR-WIN-014).- No duplicate-path check is performed despite a commented-out
//if (loggers.Any(filepath)line in source — this inactive check is not documented as active behavior; duplicate machine env vars pointing at the same file path are not deduplicated. LogWriter's underlyingStreamWriteris lazily created on firstWrite/WriteLine/WriteTimedLineaccess (if (writer.IsNull()) writer = new StreamWriter(FilePath)), not at construction time.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([ConsoleLogService constructed]) --> GetVars[Get machine environment variables]
GetVars --> Filter[Filter names matching file0-4]
Filter --> Loop[For each match]
Loop --> Register[RegisterLogFile: new LogWriter]
Register --> MapType[Map name to LogType, default Custom]
MapType --> Loop
Loop --> Done([loggers list populated])
Failure and edge-case behavior¶
- Duplicate machine environment variables pointing at the same file path each produce a separate
LogWriterinstance; no deduplication occurs. Flush()onConsoleLogServiceandLogWriterthrowsNotImplementedExceptionunconditionally — this is confirmed as-implemented, but whether any consuming application calls these members (which would surface as a runtime defect) is unknown.**- The underlying
StreamWriterfor a givenLogWriteris not created until the first log write, so a registered log file that is never written to produces no file on disk.
Related documentation¶
Note: Statements marked with
**could not be confirmed; treat as unknown until verified.
Sources¶
Console\SAIF.Console\Console\ConsoleLogService.csConsole\SAIF.Console\Console\LogWriter.cs