---
title: clsLogError
summary: API reference for clsLogError.
status: draft
owner: <owner>
last_reviewed: 2026-07-23
library: SAIF.Framework.Logging
reference_type: package
---

# clsLogError

`clsLogError` is the exception-logging entry point for hosting applications, capturing exception detail and ambient context, suppressing noisy ASP.NET ViewState errors, and optionally emailing a recipient when an error is logged.

## Purpose
- Record application exceptions (with recursive inner-exception formatting) to either a local CSV file or the remote `wsLogging` SOAP web service.
- Suppress ASP.NET ViewState tampering/disconnect errors before they are written (see [BR-004](../../business-rules.md#br-004-aspnet-viewstate-errors-are-never-logged)).
- Optionally notify a recipient by email when an error occurs.

## Context
- Namespace: `SAIF.Framework.Logging`
- Assembly/package: `SAIF.BOF.Framework.Logging` (`SAIF.Framework.Logging/SAIF.BOF.Framework.Logging.vbproj`)
- Class is `Serializable`.

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `New` | `Public Sub New(exception As Exception, ParamArray stateInfo() As Object)` | Constructs an instance, capturing exception detail and ambient context, including recursive inner-exception formatting (`ExceptionToString`). |
| `ErrorInfo` | `ReadOnly Property ErrorInfo As ErrorInfoStruct` | Exposes the populated [ErrorInfoStruct](ErrorInfoStruct.md) context struct for the constructed instance. |
| `CreateError` | `Shared Function CreateError(exception As Exception, ParamArray stateInfo() As Object) As Boolean` | Primary entry point: constructs a `clsLogError`, checks `SuppressLogging()`, and writes the error unless suppressed. |
| `CreateErrorWithEmail` | `Shared Function CreateErrorWithEmail(sendTo As String, exception As Exception, ParamArray stateInfo() As Object) As Boolean` | Same as `CreateError`, plus sends an email notification via `SAIF.Framework.Mail.SAIFMail.clsSAIFMessage.SendMail`. |
| `SuppressLogging` | `Function SuppressLogging() As Boolean` | Returns `True` if `ErrorInfo.ExceptionInfo` matches known ASP.NET ViewState noise patterns, suppressing the write. |
| `ToFile` | `Shared Sub ToFile()` | Redirects subsequent error writes to a local CSV file (throws if `IsWeb`; see [BR-003](../../business-rules.md#br-003-file-based-logging-is-prohibited-in-web-applications)). |
| `ToFile` | `Shared Sub ToFile(fileName As String)` | Same as `ToFile()`, using a caller-supplied file name. |

## Behavioral notes
- `GetBasicErrorInfo()` gathers ambient context (machine name, application name, page name, environment, current username) via `clsSecurityPrincipal` (from `SAIF.Framework.Security`)*.
- `WriteMessage` dispatches to a local file sink (if `ToFile()` was previously called) or, by default, to the `wsLogging.clsWSLogging.WriteError` SOAP operation.
- `CreateErrorWithEmail` builds a `clsSAIFMessage`, sets its `Url` from the `legacyMailServiceUrl` config setting, and always uses `"{username}@SAIF.COM"` as the sender address (see [BR-006](../../business-rules.md#br-006-email-error-notification-always-sent-to-a-fixed-corporate-email-domain)).
- All write paths are wrapped in `Try...Catch` with empty/`'gobble gobble` catch blocks, so a failure to log never propagates to the caller (see [BR-005](../../business-rules.md#br-005-logging-failures-must-never-raise-exceptions-to-the-caller)).

## Constraints and usage notes
- `ToFile()`/`ToFile(fileName)` must not be called from a web application; doing so throws `ApplicationException("Logging to files not valid for web applications.")`.
- Errors whose formatted exception info contains `"AUTHENTICATION OF VIEWSTATE FAILED"` or `"INVALID_VIEWSTATE_CLIENT_DISCONNECTED"` are silently dropped and never written.
- `CreateErrorWithEmail` depends on `SAIF.Framework.Mail`; the primary `CreateError` path does not.

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with `**` could not be confirmed; treat as unknown until verified.

## Related documentation
- [ErrorInfoStruct](ErrorInfoStruct.md)

## Sources
- `SAIF.Framework.Logging/clsLogError.vb`
- `SAIF.Framework.Logging/ErrorInfoStruct.vb`
