Skip to content

viktor-nikolaev/XeonApps.Extensions.Logging.WithProperty

Repository files navigation

XeonApps.Extensions.Logging.WithProperty

Version

Extensions methods for adding custom properties to structured logging output when using Microsoft.Extensions.Logging;

Installation

Install-Package XeonApps.Extensions.Logging.WithProperty

See NuGet

Usage

using Microsoft.Extensions.Logging.Abstractions; 

ILogger logger = loggerFactory.CreateLogger<Program>();

// inline
logger
  .WithProperty("SomeProp", "value")
  .LogInformation("User {User} logged in", "Jon");

// reassign a logger with props
logger = logger
  .WithProperty("OneProp", 22)
  .WithProperty("End", 21)
  .WithProperties(
    ("key", "value")
  )
  .WithProperties(
    new KeyValuePair<string, object>("another", "one"),
    new KeyValuePair<string, object>("some", "more"),
    new KeyValuePair<string, object>("End", "more")
  );

// will have all the added props as well as props from the template 
logger.LogInformation("Event {Event} happened", "UserLoggedOut");

Supported platforms

  • NLog
  • Serilog

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

Languages