Lightweight extension methods that attach additional properties to log messages when using Microsoft.Extensions.Logging. They help enrich log output with contextual data.
Install-Package XeonApps.Extensions.Logging.WithPropertyusing Microsoft.Extensions.Logging;
ILogger logger = loggerFactory.CreateLogger<Program>();
// Add a property inline
logger
.WithProperty("UserId", "123")
.LogInformation("User {User} logged in", "Jon");
// Create a logger with predefined properties
logger = logger
.WithProperty("AppVersion", "1.0")
.WithProperties(
("SessionId", Guid.NewGuid()),
("Country", "RU")
);
// All properties are included in each call
logger.LogInformation("Event {Event} occurred", "UserLoggedOut");- Enriches logs with contextual information using concise syntax.
- Works with NLog and Serilog via the standard logging abstractions.
- Supports adding single properties or sets of properties at once.