Skip to content

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

  1. Filter machine environment variable names matching regex ^file[0-4] (case-insensitive, lower-cased before matching).
  2. For each matching variable name, call RegisterLogFile(key, Environment.GetEnvironmentVariable(key)), which adds new LogWriter(logId, filePath) to the loggers list.
  3. LogWriter's constructor maps logId.ToLower() to a LogType (file0–file4, else Custom) via a fixed lookup dictionary (BR-WIN-014).
  4. 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.
  5. LogWriter's underlying StreamWriter is lazily created on first Write/WriteLine/WriteTimedLine access (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 LogWriter instance; no deduplication occurs.
  • Flush() on ConsoleLogService and LogWriter throws NotImplementedException unconditionally — this is confirmed as-implemented, but whether any consuming application calls these members (which would surface as a runtime defect) is unknown.**
  • The underlying StreamWriter for a given LogWriter is not created until the first log write, so a registered log file that is never written to produces no file on disk.

Note: Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Console\SAIF.Console\Console\ConsoleLogService.cs
  • Console\SAIF.Console\Console\LogWriter.cs