-
Notifications
You must be signed in to change notification settings - Fork 1
Serilog
Arnel Robles edited this page Sep 28, 2026
·
1 revision
Structured logging for mapping calls, with timing and an optional slow-mapping warning.
using Mapsicle.Serilog;
using Serilog;
var logger = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Debug()
.CreateLogger();
// Global: every MapWithLogging call writes to this logger
SerilogExtensions.UseSerilog(logger);UseSerilog also sets Mapper.Logger, so the core's own diagnostics (depth limits, cycles) go to
the same logger at Information level.
var dto = user.MapWithLogging<UserDto>();
// [Mapsicle] Mapped {SourceType} -> {DestType} in {ElapsedMs:F2}ms (cached: {IsCached})
var dtos = users.MapCollectionWithLogging<UserDto>();
// [Mapsicle] Mapped collection of {Count} items to {DestType} in {ElapsedMs:F2}msThe logger comes from UseSerilog, not from the call. A mapping that throws is logged at Error and
rethrown.
Off by default. Turn it on when you call UseSerilog:
SerilogExtensions.UseSerilog(logger, options =>
{
options.SlowMappingThreshold = TimeSpan.FromMilliseconds(50);
});
var dto = largeObject.MapWithLogging<LargeDto>();
// Over 50 ms, also logs at Warning: [Mapsicle] Slow mapping detected: ...using (var scope = SerilogExtensions.BeginMappingScope("OrderProcessing"))
{
foreach (var order in orders)
{
order.MapWithLogging<OrderDto>();
scope.RecordMapping();
}
}
// On dispose: [Mapsicle] Completed OrderProcessing: {MappingCount} mappings in {ElapsedMs:F2}msThe scope counts only what you record with RecordMapping() and RecordError(). Mapping calls
inside it are not counted or tagged automatically. It logs through the logger UseSerilog set, so
call that first.
Mapsicle
Packages
- Core
- Fluent
- EntityFramework
- Validation
- NamingConventions
- Serilog
- Dapper
- AspNetCore
- Json
- Caching
- Audit
- DataAnnotations
Reference