Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.2 KB

File metadata and controls

40 lines (29 loc) · 1.2 KB

XeonApps.Extensions.Logging.WithProperty

Version

Lightweight extension methods that attach additional properties to log messages when using Microsoft.Extensions.Logging. They help enrich log output with contextual data.

Installation

Install-Package XeonApps.Extensions.Logging.WithProperty

Usage

using 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");

Why use it?

  • 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.