Skip to content

Write contextual diagnostic log entry

This operation centralizes diagnostic logging for the library. Every log call routes through it, ensuring each message reaches log4net carrying the current host address, request URL, application name, and a reduced call-stack trail — so authentication activity can be reconstructed from the logs even though the individual authenticator classes never format their own log entries.

Field Value
Operation ID write-contextual-diagnostic-log-entry
Trigger Library code calls LogInfo, LogWarn, LogError, or LogDebug.
Inputs Message text, current HttpContext, current stack trace
Outputs Formatted log4net entry
Primary components mdlLogging.LogInfo, mdlLogging.LogWarn, mdlLogging.LogError, mdlLogging.LogDebug, mdlLogging.LogMsg
Entry point SAIF.Framework.SecurityModule\mdlLogging.vb

Steps

  1. On first use, lazily initialize m_log by calling LogManager.GetLogger(GetType(clsSecurityModule).Name), so the logger is created once per application lifetime rather than on every call.
  2. Route the severity-specific helper the caller invoked (LogInfo, LogWarn, LogError, or LogDebug) through LogMsg, passing the matching log4net formatter delegate.
  3. Inside LogMsg, read the application path, host address, and request URL from HttpContext.Current.Request.
  4. Build a call-stack summary by scanning StackTrace.GetFrames(): keep only frames declared on clsSecurityModule, skip helper-frame names beginning with ASSERT or GETSTACKFRAMES, reverse the remaining sequence so it reads outer-to-inner, and join the method names with ->.
  5. Format the final message as {hostAddress},{requestUrl},{applicationName}->{stackFrames},{message} and invoke the requested log4net delegate with that string.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Logging helper called]) --> S1[Get or create logger]
    S1 --> S2[Collect request context]
    S2 --> S3[Derive stack-frame trail]
    S3 --> S4[Format combined message]
    S4 --> EndOk([Write log4net entry])

Failure and edge-case behavior

  • The operation assumes HttpContext.Current and HttpContext.Current.Request are available whenever logging is invoked; it does not guard against a null ambient context.
  • The reduced stack trace includes only frames declared on clsSecurityModule, so it does not show intermediate frames when a log call originates from other helper classes in the call chain.

Sources

  • SAIF.Framework.SecurityModule\mdlLogging.vb