---
title: Record login event
summary: Append a login event to the library's monthly CSV login log.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-07-30
library: SAIF.Framework.Logging
reference_type: package
operation_id: LOG-OP-006
trigger: Caller invokes clsLoginLog.LogItem(...)
---

# 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](../business-rules.md#br-005-logging-failures-must-never-raise-exceptions-to-the-caller)).
2. Determine the output directory and the caller's IP address.
   - When `HttpContext.Current Is Nothing`, use `CurDir()` as the log path and hard-code `127.0.0.1` as the IP address.
   - Otherwise use `Request.MapPath("/") & "Logs\"` as the directory and copy `Request.UserHostAddress`.
3. Open the shared writer once, if it does not already exist: `File.AppendText(LogPath & "Login" & Today.Month & Today.Year & ".log")`.
4. Append a comma-delimited line — `Now.ToString`, the supplied `inUserID`, and the resolved IP address — then flush the writer.
5. On failure: swallow the exception and return without notifying the caller ([BR-005](../business-rules.md#br-005-logging-failures-must-never-raise-exceptions-to-the-caller)).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
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](../business-rules.md#br-005-logging-failures-must-never-raise-exceptions-to-the-caller)).

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Configuration](../configuration.md)

## Sources
- `SAIF.Framework.Logging/clsLoginLog.vb`
