Skip to content

viktor-nikolaev/XeonApps.Extensions.Logging.WithProperty

Repository files navigation

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.

About

Extensions methods for adding custom properties to structured logging output

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages