Skip to content

Record login event

This is a legacy helper that appends a single, minimal login record to a monthly flat file. It picks the log directory from the current hosting context, reuses one shared file handle across successive calls, and suppresses any write failure so a logging problem never blocks the host application's login flow.

Field Value
Operation ID LOG-OP-006
Trigger Caller invokes clsLoginLog.LogItem(...).
Inputs User ID.
Outputs CSV append side effect; no return value.
Primary components clsLoginLog.LogItem
Entry point SAIF.Framework.Logging/clsLoginLog.vb

Steps

  1. Enter the method-wide Try...Catch so this operation remains best-effort from start to finish (BR-005).
  2. Determine the output directory and the caller's IP address.
  3. When HttpContext.Current Is Nothing, use CurDir() as the log path and hard-code 127.0.0.1 as the IP address.
  4. Otherwise use Request.MapPath("/") & "Logs\" as the directory and copy Request.UserHostAddress.
  5. Open the shared writer once, if it does not already exist: File.AppendText(LogPath & "Login" & Today.Month & Today.Year & ".log").
  6. Append a comma-delimited line — Now.ToString, the supplied inUserID, and the resolved IP address — then flush the writer.
  7. On failure: swallow the exception and return without notifying the caller (BR-005).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([LogItem request]) --> Host{HttpContext.Current present?}
    Host -->|No| Local[Use CurDir and 127.0.0.1]
    Host -->|Yes| Web[Use web Logs directory and UserHostAddress]
    Local --> Writer{Writer already open?}
    Web --> Writer
    Writer -->|No| Open[Open monthly login file]
    Writer -->|Yes| Append[Append login row]
    Open --> Append
    Append --> End([Flush and return])

Failure and edge-case behavior

  • Non-web callers always record 127.0.0.1 rather than attempting to discover an actual local network address.
  • The file handle is opened once and reused thereafter, so the target month/year file name is fixed for the lifetime of the process; it is not re-evaluated on later calls.
  • Write failures are swallowed silently, preserving best-effort behavior at the cost of leaving gaps in the login log with no diagnostic trace (BR-005).

Sources

  • SAIF.Framework.Logging/clsLoginLog.vb