Logging

Overview

Smartstore uses Microsoft.Extensions.Logging with Serilogarrow-up-right for structured logging. Configuration lives in appsettings.json and can be overridden in Config/usersettings.json. Each log event is enriched with request data such as IP address, URL, customer ID, and user name. Events are written to rolling text files under App_Data/Logs and to the database table Log via a custom Serilog sink. Logs are viewable in the admin area under System > Log.

Writing log entries

Inject ILogger<T> into any service or controller to write structured messages:

public class MyService
{
    private readonly ILogger<MyService> _logger;

    public MyService(ILogger<MyService> logger)
    {
        _logger = logger;
    }

    public void DoWork()
    {
        _logger.LogInformation("Processing started");
    }
}

Smartstore can also inject a logger via a public property. Add the property with a default NullLoggerarrow-up-right so it is always non-null and the container will replace it with a contextual logger at runtime:

Controllers inheriting from SmartController already declare this Logger property, so you usually only add it to custom services that need optional logging without constructor injection.

Request logging

The platform enables request logging middleware through UseRequestLogging(). It logs each HTTP request once with method, path, status code, elapsed time, and user context:

Activity log

IActivityLogger records high-level user actions such as logins, checkouts, or admin changes. Entries are stored in the ActivityLog table and surfaced in the admin UI:

Notifications

Use INotifier to queue toast messages for the current request. They appear on the next page load:

Log cleanup Smartstore periodically purges old log entries from the database using the "Delete logs" scheduled task. By default, this task retains all entries with a level of Error or higher to ensure critical diagnostic data isn't lost.

If your application generates a high volume of errors, the Log table can grow significantly (e.g., hundreds of thousands of rows) and the cleanup task might become overwhelmed. To prevent this, you can opt-in to a more aggressive cleanup by using a hidden setting:

  • Go to Admin > Configuration > Settings > All Settings.

  • Edit the setting CommonSettings.MinLogLevelToRetain.

  • Set its value to Fatal.

Once set, the automated cleanup task will also delete regular Error logs, keeping only Fatal errors indefinitely.

Last updated

Was this helpful?