Mango.Nop.Libraries/Mango.Nop.Services/docs/LOGGING/README.md

1.9 KiB

NopLogWriter — Logging Bridge

Part of Mango.Nop.Services. See Mango.Nop.Services/README.md for project overview. For AyCode base logging types (AcLogItemWriterBase, AcLogItem, log levels) see AyCode.Core/AyCode.Core/docs/LOGGING/README.md.

Overview

Bridges AyCode logging to nopCommerce's Nop.Core.Domain.Logging.Log table via direct DB insert.

NopLogWriter

Feature Detail
Inherits AcLogItemWriterBase<AcLogItem> (AyCode.Core)
Log level mapping AyCode Detail/Trace/Debug/Info -> nopCommerce Information; Suggest/Warning -> Warning; Error -> Error
Direct DB insert Uses NopLoggerMsSqlNopDataProvider with TransactionScope(Suppress) to avoid transaction conflicts

Constructor: (INopLoggerMsSqlNopDataProvider, CommonSettings, CustomerSettings, IWebHelper, Nop.Services.Logging.ILogger, string? categoryName)

NopLoggerMsSqlNopDataProvider

Extends MsSqlNopDataProvider. Provides isolated DB access for log writes.

Method Purpose
InsertLogItem<T>() Sync insert with own TransactionScope(Suppress, ReadUncommitted)
InsertLogItemAsync<T>() Async insert with own TransactionScope(Suppress, ReadUncommitted)

The TransactionScope(Suppress) is critical — without it, log writes would participate in the caller's transaction, causing nesting conflicts and potential deadlocks.

Integration Point

Application code -> Mango.Nop.Core.Loggers.ILogger (extends IAcLoggerBase)
                    -> Logger<TCategory> (extends AcLoggerBase, delegates to IAcLogWriterBase[])
                        -> NopLogWriter -> Nop Log table (direct SQL insert)
                        -> [Other AyCode log writers: console, file, SignalR, etc.]

Exception: MgBackgroundServiceBase uses Nop.Services.Logging.ILogger directly (nopCommerce logger), not the Mango wrapper.