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¶
- Enter the method-wide
Try...Catchso this operation remains best-effort from start to finish (BR-005). - Determine the output directory and the caller's IP address.
- When
HttpContext.Current Is Nothing, useCurDir()as the log path and hard-code127.0.0.1as the IP address. - Otherwise use
Request.MapPath("/") & "Logs\"as the directory and copyRequest.UserHostAddress. - Open the shared writer once, if it does not already exist:
File.AppendText(LogPath & "Login" & Today.Month & Today.Year & ".log"). - Append a comma-delimited line —
Now.ToString, the suppliedinUserID, and the resolved IP address — then flush the writer. - 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.1rather 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).
Related documentation¶
Sources¶
SAIF.Framework.Logging/clsLoginLog.vb